Skip to content

Commit d5f08af

Browse files
committed
more flexible classpath setting
1 parent eda2593 commit d5f08af

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/jvm.jl

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,16 @@ end
121121

122122
@static is_unix() ? (const sep = ":") : nothing
123123
@static is_windows() ? (const sep = ";") : nothing
124-
cp=Array{String}(0)
125-
opts=Array{String}(0)
124+
cp=Set{String}()
125+
opts=Set{String}()
126126

127127
function addClassPath(s::String)
128128
if isloaded()
129129
warn("JVM already initialised. This call has no effect")
130130
return
131131
end
132132
if s==""; return; end
133-
if endswith(s, "/*")
133+
if endswith(s, "/*") && isdir(s[1:end-2])
134134
for x in s[1:end-1] .* readdir(s[1:end-2])
135135
if endswith(x, ".jar")
136136
push!(cp, x)
@@ -148,7 +148,7 @@ function init()
148148
if isempty(cp)
149149
init(opts)
150150
else
151-
init(vcat(opts, reduce((x,y)->string(x,sep,y),"-Djava.class.path=$(cp[1])",cp[2:end])))
151+
init(vcat(collect(opts), reduce((x,y)->string(x,sep,y),"-Djava.class.path=$(collect(cp)[1])",collect(cp)[2:end])))
152152
end
153153
end
154154

@@ -158,12 +158,9 @@ assertloaded() = isloaded()?nothing:error("JVM not initialised. Please run init(
158158
assertnotloaded() = isloaded()?error("JVM already initialised"):nothing
159159

160160
# Pointer to pointer to pointer to pointer alert! Hurrah for unsafe load
161-
function init{T<:AbstractString}(opts::Array{T, 1})
161+
function init(opts)
162162
assertnotloaded()
163-
opt = Array{JavaVMOption}(length(opts))
164-
for i in 1:length(opts)
165-
opt[i]=JavaVMOption(pointer(opts[i]), C_NULL)
166-
end
163+
opt = [JavaVMOption(pointer(x), C_NULL) for x in opts]
167164
ppjvm=Array{Ptr{JavaVM}}(1)
168165
ppenv=Array{Ptr{JNIEnv}}(1)
169166
vm_args = JavaVMInitArgs(JNI_VERSION_1_6, convert(Cint, length(opts)), convert(Ptr{JavaVMOption}, pointer(opt)), JNI_TRUE)

0 commit comments

Comments
 (0)