Skip to main content

run_java

Function run_java 

Source
pub fn run_java(
    class_name: &str,
    filename: &str,
    java_class: &str,
    full_class_name: &str,
    javac_raw: &str,
    java_raw: &str,
    stdin_bytes: &[u8],
) -> Result<Vec<u8>, JavaError>
Expand description

Re-export the core error type and runtime helpers. Compile (if needed) and run a generated Java class, returning raw stdout bytes.

Both the compile step (javac) and the run step (java) are guarded by a per-class-name file lock so that concurrent invocations cooperate correctly. A .done sentinel and an optimistic pre-check skip recompilation on subsequent calls without acquiring the lock.

  • class_name — bare class name; used as the temp-dir name.
  • filename"<class_name>.java", written inside the temp dir.
  • java_class — complete .java source to write.
  • full_class_name — package-qualified class name passed to java.
  • javac_raw — raw javac = "..." option string (shell-expanded).
  • java_raw — raw java = "..." option string (shell-expanded).
  • stdin_bytes — bytes to pipe to the child process’s stdin (may be empty).

§Errors

Returns JavaError::Io if the temp directory, source file, or lock file cannot be created, or if javac/java cannot be spawned. Returns JavaError::CompilationFailed if javac exits with a non-zero status. Returns JavaError::RuntimeFailed if java exits with a non-zero status.

§Examples

use inline_java_core::run_java;

let src = "public class Greet {
    public static void main(String[] args) {
        System.out.print(\"hi\");
    }
}";
let output = run_java("Greet", "Greet.java", src, "Greet", "", "", &[]).unwrap();
assert_eq!(output, b"hi");