Skip to content

Commit

Permalink
only copy jar if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
mooreniemi committed Jun 14, 2021
1 parent 7329ab4 commit 82b470e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 9 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ use std::env;
use std::path::Path;

fn main() {
// We copy the .gitignore'd mvn package output into jassets if it exists
let input_path = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap())
.join("java_wrapper/target/suntan-1.0-SNAPSHOT.jar");
dbg!(&input_path);
let output_path =
Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("jassets/suntan.jar");
dbg!(&output_path);
let res = std::fs::copy(input_path, output_path).expect("must copy jar");
dbg!(res);
if input_path.exists() {
dbg!(&input_path);
let output_path =
Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("jassets/suntan.jar");
dbg!(&output_path);
let res = std::fs::copy(input_path, output_path).expect("must copy jar");
dbg!(res);
}
}
10 changes: 7 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ fn run(
// j4rs Rust -> Java setup
// FIXME: is this the best way to handle the underlying java dependency?
// the jar must be prebuilt already with maven, using mvn package, then build.rs moves it into jassets
let jassets_path =
Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("jassets/suntan.jar");
let entry = ClasspathEntry::new(jassets_path.as_path().to_str().expect("valid path"));
let jassets_path = Path::new(&env!("CARGO_MANIFEST_DIR")).join("jassets/suntan.jar");
let entry = ClasspathEntry::new(
jassets_path
.as_path()
.to_str()
.expect("valid jassets classpath"),
);
let jvm: Jvm = JvmBuilder::new()
.classpath_entry(entry)
.build()
Expand Down

0 comments on commit 82b470e

Please sign in to comment.