可以让 JNI 支持类路径中的通配符扩展吗? [英] Can JNI be made to honour wildcard expansion in the classpath?

查看:35
本文介绍了可以让 JNI 支持类路径中的通配符扩展吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过 JNI 调用 Java 的 C 二进制文件.我将 CLASSPATH 设置为 somedir/* 以获取 somedir 中的所有 jar.

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 cannot be found. When I run

java that.class's.name 

在同一命令行中,已成功找到该类.如果我将 somedir/中的所有 jar 显式添加到类路径中,一切都会很好,但这会导致我想避免的 very 长类路径.

from the same command line, the class is successfully found. If I explicitly add all the jars in somedir/ to the classpath, everything works great, but that leads to a very long classpath which I'd like to avoid.

通过 JNI 执行的 JVM 是否支持类路径的通配符扩展?可以这样做吗?

Does a JVM executed via JNI honour wildcard expansion of the classpath? Can it be made to do so?

推荐答案

我通过阅读热点源码找到了答案.

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

只有通过 CLASSPATH-cp/-classpath 传递的路径才能进行通配符扩展.然后这些作为系统属性通过 -Djava.class.path 传递给正在运行的 JVM.

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.

您通过 JVMOptions 结构告诉 JNI 调用的 JVM 一个类路径,该结构可能包括 -Djava.class.path-classpath 不会必然受到尊重(实际上,不是通过热点实现).由于 java.class.path 作为系统属性直接传递给 JVM,它不会扩展通配符,因此通配符不起作用.

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.

这篇关于可以让 JNI 支持类路径中的通配符扩展吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆