| Crates.io | javac |
| lib.rs | javac |
| version | 0.1.0 |
| created_at | 2026-01-11 22:25:32.684995+00 |
| updated_at | 2026-01-11 22:25:32.684995+00 |
| description | A build-time dependency for Cargo build scripts and unit tests to assist in invoking the native Java compiler to compile Java source files into class files. |
| homepage | |
| repository | https://github.com/jni-rs/jni-rs |
| max_upload_size | |
| id | 2036596 |
| size | 63,579 |
A library for Cargo build scripts
to compile Java source files into .class files. This crate provides a simple
builder API similar to the cc crate, making it easy to compile Java code as
part of your Rust build process.
This crate does not compile code itself; it calls out to the javac compiler
on your system (located via JAVA_HOME or PATH). It will automatically
handle cross-platform differences and properly encode file paths.
First, add javac as a build dependency in your Cargo.toml:
[build-dependencies]
javac = "0.1"
Then, in your build.rs:
fn main() {
javac::Build::new()
.file("java/com/example/HelloWorld.java")
.compile();
}
For more complex scenarios:
fn main() {
javac::Build::new()
.files(&["java/Foo.java", "java/Bar.java"])
.source_dir("java") // Recursively compile all .java files
.classpath("lib/dependency.jar")
.release("11") // Java 11 compatibility
.encoding("UTF-8")
.debug(true)
.compile();
}
The compiled .class files will be placed in $OUT_DIR/javac-build/classes/
by default, or you can specify a custom output directory with .output_dir().
javac must be installedjavac -verbose output must be compatible with the OpenJDK compiler which includes
[wrote /path/to/Name.class] lines, in order to track what .class files are written by
the compiler.JAVA_HOME environment variable must be set, or javac must be in PATHRefer to the documentation for detailed API documentation.
This project is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.