Is it possible to make a JNI to evaluate the expansion of wildcards in a classpath?

I have a binary C code that is called in Java via JNI. I set CLASSPATH for somedir / * to collect all banks in somedir.

When I run the binary, the class definition cannot be found. When i started

java that.class's.name 

from the same command line, the class was successfully found. If I explicitly add all banks in somedir / to the classpath, everything works fine, but this leads to a very long classpath that I would like to avoid.

Is the JVM running through the JNI extension of the pathpath class wildcard extension? Can this be done?

+6
source share
2 answers

I understood the answer by reading the source code of hotspot.

Only paths passing through CLASSPATH or -cp / -classpath are subject to wildcard expansion. They are then passed as a system property to start the JVM through -Djava.class.path .

You tell the JVM with the JNI call about the class path using the JVMOptions structure, which may include -Djava.class.path , but -classpath will not necessarily execute (and in practice this is not an implementation of Hotspot). Since java.class.path directly passed to the JVM as a system property, it does not decrypt the wildcard, and therefore the wildcard will not work.

+7
source

Not. No, he can not. Using JNI does not help.

The way you do this is to implement your own classloader (in Java), but this classloader should be in the CLASSPATH template.

You could, of course, set CLASSPATH to your extended form before invoking the JVM. This will work and can be done through a shell script (no JNI required).

+3
source

Source: https://habr.com/ru/post/908668/


All Articles