@@ -232,16 +232,16 @@ addJarsToClassPath(args...) = isloaded() ?
232
232
@warn (" JVM already initialized. This call has no effect" ) :
233
233
_addJarsToClassPath (args... )
234
234
235
- addOpts (s:: String ) = isloaded () ? @warn (" JVM already initialised. This call has no effect" ) : push! (opts, s)
236
-
237
- function init ()
238
- if isempty (cp)
239
- init (opts)
235
+ function addOpts (s:: String )
236
+ if isloaded ()
237
+ @warn (" JVM already initialised. This call has no effect" )
240
238
else
241
- ccp = collect (cp)
242
- options = collect (opts)
243
- classpath = " -Djava.class.path=" * join (ccp,sep)
244
- init (vcat (options, classpath))
239
+ m = match (r" ^-Djava.class.path=(.*)" ,s)
240
+ if m != nothing
241
+ addClassPath (String (m. captures[1 ]))
242
+ else
243
+ push! (opts, s)
244
+ end
245
245
end
246
246
end
247
247
@@ -267,8 +267,46 @@ isloaded() = isdefined(JavaCall, :jnifunc) && isdefined(JavaCall, :penv) && penv
267
267
assertloaded () = isloaded () ? nothing : throw (JavaCallError (" JVM not initialised. Please run init()" ))
268
268
assertnotloaded () = isloaded () ? throw (JavaCallError (" JVM already initialised" )) : nothing
269
269
270
+ """
271
+ JavaCall.init(opts::Array{String,1})
272
+ JavaCall.init(opt1::String,opt2::String, ...)
273
+ JavaCall.init()
274
+
275
+ Initialize JavaCall with JVM options.
276
+
277
+ As of JavaCall v0.7.4 new options passed to init will be appended
278
+ to previous options added with addClasspath and addOpts.
279
+
280
+ Once init() is called, addClasspath and addOpts no longer have any effect.
281
+
282
+ See http://juliainterop.github.io/JavaCall.jl/methods.html
283
+
284
+ Example
285
+ JavaCall.init(["-Xmx512M", "-Djava.class.path=$(@__DIR__ ) ", "-verbose:jni", "-verbose:gc"])
286
+ """
287
+ function init (opts:: Array{String,1} )
288
+ addOpts .(opts)
289
+ init ()
290
+ end
291
+
292
+ # Accept options strings as a set of arguments
293
+ init (opts:: Array{AbstractString,1} ) = init (String .(opts))
294
+ init (opts:: Vararg{AbstractString,N} ) where N = init (String .([opts... ]))
295
+
296
+ function init ()
297
+ if isempty (cp)
298
+ _init (opts)
299
+ else
300
+ ccp = collect (cp)
301
+ options = collect (opts)
302
+ classpath = " -Djava.class.path=" * join (ccp,sep)
303
+ _init (vcat (options, classpath))
304
+ end
305
+ end
306
+
307
+ # Below is the original main initialization option
270
308
# Pointer to pointer to pointer to pointer alert! Hurrah for unsafe load
271
- function init (opts)
309
+ function _init (opts)
272
310
assertnotloaded ()
273
311
assertroottask_or_goodenv ()
274
312
opt = [JavaVMOption (pointer (x), C_NULL ) for x in opts]
0 commit comments