Skip to content

Commit

Permalink
Use WinReg to set JAVA_HOME (#38)
Browse files Browse the repository at this point in the history
* Use WinReg to set JAVA_HOME

* Add back using Base.Dates
  • Loading branch information
AndyGreenwell authored and aviks committed Jul 5, 2016
1 parent 0886ca7 commit 902da00
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
julia 0.4
Compat 0.8.4
WinReg
2 changes: 1 addition & 1 deletion src/JavaCall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export JavaObject, JavaMetaClass,
@jimport, jcall, jfield, isnull,
getname, listmethods, getreturntype, getparametertypes

# using Debug
using Base.Dates
using WinReg
using Compat
import Compat.String

Expand Down
10 changes: 10 additions & 0 deletions src/jvm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ const JNI_ENOMEM = convert(Cint, -4) #/* not enough memory */
const JNI_EEXIST = convert(Cint, -5) #/* VM already created */
const JNI_EINVAL = convert(Cint, -6) #/* invalid arguments */

function javahome_winreg()
keypath = "SOFTWARE\\JavaSoft\\Java Development Kit"
value = querykey(WinReg.HKEY_LOCAL_MACHINE, keypath, "CurrentVersion")
keypath *= "\\"*value
return querykey(WinReg.HKEY_LOCAL_MACHINE, keypath, "JavaHome")
end

@static is_unix() ? (global const libname = "libjvm") : (global const libname = "jvm")

Expand All @@ -25,7 +31,11 @@ function findjvm()

if haskey(ENV,"JAVA_HOME")
push!(javahomes,ENV["JAVA_HOME"])
else
@static is_windows() ? ENV["JAVA_HOME"] = javahome_winreg() : nothing
@static is_windows() ? push!(javahomes, ENV["JAVA_HOME"]) : nothing
end

if isfile("/usr/libexec/java_home")
push!(javahomes,chomp(readstring(`/usr/libexec/java_home`)))
end
Expand Down

0 comments on commit 902da00

Please sign in to comment.