Embeddable Java Virtual Machine and Java compiler implementation.
Try the Java playground to compile and run Java entirely in your browser, without installing a JDK. JShell evaluates Java snippets, expressions, and methods in a persistent interactive session.
The Ristretto java runtime can be installed using the following methods:
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/theseus-rs/ristretto/releases/latest/download/ristretto_java-installer.sh | shirm https://github.com/theseus-rs/ristretto/releases/latest/download/ristretto_java-installer.ps1 | iexFor more information, and additional installations instructions (cargo, homebrew, msi), visit the ristretto site.
Run a compiled HelloWorld.class in the current directory using its class name (without .class):
java -cp . HelloWorldTo embed the JVM in a Rust application, add the dependencies:
cargo add ristretto_vm
cargo add tokioPlace HelloWorld.class in the current directory and use this in src/main.rs:
use ristretto_vm::{ClassPath, ConfigurationBuilder, Result, VM};
#[tokio::main]
async fn main() -> Result<()> {
let configuration = ConfigurationBuilder::new()
.class_path(ClassPath::from(&["."]))
.main_class("HelloWorld")
.build()?;
let vm = VM::new(configuration).await?;
vm.invoke_main::<&str>(&[]).await?;
Ok(())
}Run the application with cargo run.
The javac compiler is available as a separate Cargo package:
cargo install ristretto_javac
javac -d classes HelloWorld.javaRust applications can also embed and reuse the compiler:
use ristretto_vm::{Compiler, CompilerError};
#[tokio::main]
async fn main() -> Result<(), CompilerError> {
let compiler = Compiler::default().await?;
compiler.compile(&["-d", "classes", "HelloWorld.java"]).await?;
Ok(())
}- Standard runtime classes backed by LTS versions of AWS Corretto.
- Flexible class loading from directories, JARs, JMODs, JImage files, and URLs.
- Built-in support for reading, writing, and strictly verifying Java bytecode.
- A
javac-compatible CLI and reusable file or in-memory Rust compiler API. - Interpreter support for all Java byte codes including invokedynamic.
- Fully asynchronous, non-blocking execution using Rust async/await for:
- java.lang.Process
- java.lang.Thread
- java.io & java.nio
- java.net
- A low-pause, concurrent, and parallel mark-and-sweep garbage collector.
- Parallel Just-In-Time (JIT) compilation for x86-64, aarch64, s390x, and riscv64 architectures.
- WebAssembly (WASM) compilation support for single-threaded edge and browser deployments.
- Native Maven POM (Project Object Model) parsing.
- Asynchronous JVM dependency resolution with graph introspection and extensible artifact storage.
The Java runtime requires hundreds of native methods. This project aims to provide Rust equivalents
for these methods. If a native method is called that is not implemented, the program throw a
java.lang.UnsatisfiedLinkError. Please submit a pull request, or open an issue if you need a
specific native method implemented.
Support for the Security Manager is not implemented and there are no plans to implement it. The security manager has been deprecated; see: JEP 411
System.getSecurityManager() will always return null, and System.setSecurityManager() will
throw an exception.
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.