Can JNI be made to honour wildcard expansion in the classpath?

前端 未结 2 1033
北荒
北荒 2021-01-12 18:20

I have a C binary that calls out to Java via JNI. I set CLASSPATH to somedir/* to pick up all the jars in somedir.

When I run the binary, a required class definition

2条回答
  •  长发绾君心
    2021-01-12 19:03

    I figured out the answer by reading the hotspot source code.

    Only paths passed via either CLASSPATH or -cp / -classpath are subject to wildcard expansion. These are then passed as a system property to the running JVM via -Djava.class.path.

    You tell a JNI-invoked JVM about a classpath via a JVMOptions structure, which may include -Djava.class.path but -classpath will not necessarily be honoured (and in practice, isn't by the hotspot implementation). Since java.class.path is directly passed to the JVM as a system property, it doesn't get wildcard expanded and therefore wildcards won't work.

提交回复
热议问题