可以让 JNI 支持类路径中的通配符扩展吗?

编程入门 行业动态 更新时间:2024-10-18 03:31:28
本文介绍了可以让 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 支持类路径中的通配符扩展吗?

本文发布于:2023-08-01 12:36:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1268424.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通配符   路径   JNI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!