Skip to content

Commit b57f0ef

Browse files
ExpandingMandfdx
authored andcommitted
improvedi libjvm discovery (#84)
* improved libjvm discovery * fixed libjvm search * fixed libexec call
1 parent 8af174a commit b57f0ef

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/jvm.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const JNI_ENOMEM = convert(Cint, -4) #/* not enough memory */
1616
const JNI_EEXIST = convert(Cint, -5) #/* VM already created */
1717
const JNI_EINVAL = convert(Cint, -6) #/* invalid arguments */
1818

19+
const JAVA_HOME_CANDIDATES = ["/usr/lib/jvm/default-java/",
20+
"/usr/lib/jvm/default/"]
21+
1922
function javahome_winreg()
2023
try
2124
keypath = "SOFTWARE\\JavaSoft\\Java Runtime Environment"
@@ -40,19 +43,18 @@ function findjvm()
4043
javahomes = Any[]
4144
libpaths = Any[]
4245

43-
if haskey(ENV,"JAVA_HOME")
44-
push!(javahomes,ENV["JAVA_HOME"])
46+
if haskey(ENV, "JAVA_HOME")
47+
push!(javahomes, ENV["JAVA_HOME"])
4548
else
46-
@static Sys.iswindows() ? ENV["JAVA_HOME"] = javahome_winreg() : nothing
47-
@static Sys.iswindows() ? push!(javahomes, ENV["JAVA_HOME"]) : nothing
48-
end
49-
50-
if isfile("/usr/libexec/java_home")
51-
push!(javahomes,chomp(read(`/usr/libexec/java_home`, String)))
49+
@static if Sys.iswindows()
50+
ENV["JAVA_HOME"] = javahome_winreg()
51+
push!(javahomes, ENV["JAVA_HOME"])
52+
end
5253
end
54+
isfile("/usr/libexec/java_home") && push!(javahomes, chomp(read(`/usr/libexec/java_home`, String)))
5355

54-
if isdir("/usr/lib/jvm/default-java/")
55-
push!(javahomes, "/usr/lib/jvm/default-java/")
56+
for fname JAVA_HOME_CANDIDATES
57+
isdir(fname) && push!(javahomes, fname)
5658
end
5759

5860
push!(libpaths, pwd())
@@ -70,8 +72,8 @@ function findjvm()
7072
push!(libpaths, joinpath(n, "jre", "lib", "i386", "server"))
7173

7274
push!(libpaths, joinpath(n, "lib", "i386", "server"))
73-
end
74-
end
75+
end
76+
end
7577
push!(libpaths, joinpath(n, "jre", "lib", "server"))
7678
push!(libpaths, joinpath(n, "lib", "server"))
7779
end
@@ -89,7 +91,7 @@ function findjvm()
8991
Libdl.dlopen(joinpath(bindir,m[1]))
9092
end
9193
global libjvm = Libdl.dlopen(libpath)
92-
println("Loaded $libpath")
94+
@debug("Loaded $libpath")
9395
return
9496
end
9597
end

0 commit comments

Comments
 (0)