Skip to content

Commit

Permalink
More tweaks to how java homes are detected
Browse files Browse the repository at this point in the history
  • Loading branch information
jjlauer committed Nov 3, 2023
1 parent 9d9da92 commit cbbc601
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/fizzed/jne/JavaHomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ static public JavaHome fromDirectory(Path javaHomeDir, boolean requireReleaseFil
throw new FileNotFoundException("Java lib directory " + javaLibDir + " was not found in " + javaHomeDir);
}

// Test #3: must also have jmods and/or a jre
final Path jmodsDir = javaHomeDir.resolve("jmods");
if (!Files.isDirectory(jmodsDir)) {
final Path jreDir = javaHomeDir.resolve("jre");
if (!Files.isDirectory(jreDir)) {
final Path rtJarFile = javaLibDir.resolve("rt.jar");
if (!Files.exists(rtJarFile)) {
throw new FileNotFoundException("Java jmods/jre directory not found in " + javaHomeDir);
}
}
}

final String javacExeFileName = NativeTarget.resolveExecutableFileName(thisOs, "javac");
final Path _javacExeFile = javaHomeDir.resolve("bin").resolve(javacExeFileName);
final Path javacExeFile;
Expand All @@ -98,6 +110,7 @@ static public JavaHome fromDirectory(Path javaHomeDir, boolean requireReleaseFil
if (requireReleaseFile){
throw new FileNotFoundException("Java release file " + releaseFile + " was not found in " + javaHomeDir);
}

// otherwise, we could do "java -version" to try and detect it
try {
String versionOutput = executeJavaVersion(javaExeFile);
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit cbbc601

Please sign in to comment.