Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running JVM from C++ code and setting classpath

I'm trying to create JVM 7 from C++ code and struggling with setting the right classpath. I want to specify a classpath using wildcards: e.g. /path/to/* (to include all the jars in the folder to the classpath)

If I'm setting a classpath via

options[0].optionString = "-Djava.class.path=/path/to/*;"; 

then my class is not found. I tried backslashes (I'm using Windows 8), with and without semicolon, nothing helped. This actually does not work from a command line either.

Then I tried to provide a "-cp" option, but in this case a JVM failed to be created. I tried:

options[0].optionString = "-cp=/path/to/*";

options[0].optionString = "-cp /path/to/*"; 

options[0].optionString = "-classpath=/path/to/*"; 

options[0].optionString = "-classpath /path/to/*"; 

options[0].optionString = "-cp"; 
options[0].extraInfo = "/path/to/*"; 

options[0].optionString = "-cp"; 
options[1].optionString = "/path/to/*"; 

None of those helped.

Do you have an idea how to provide a classpath with wildcards when creating a JVM from C++?

Thanks in advance

like image 836
Vyacheslav Avatar asked Mar 21 '15 22:03

Vyacheslav


1 Answers

You will need to perform the expansion yourself because this is a feature of the Java launcher, not a feature of the JNI API. See the SetClassPath function in the launcher source, which calls the internal JLI_WildcardExpandClasspath function and then adds a -Djava.class.path option.

like image 164
Brett Kail Avatar answered Sep 29 '22 23:09

Brett Kail