gpt4 book ai didi

java - 使用 Java 9 将自定义 JMOD 添加到模块路径

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:22:14 24 4
gpt4 key购买 nike

我用这样的 jmod 工具创建了一个简单的 JMOD 文件

$JAVA_HOME/bin/jmod create --class-path classes test/samples.jmod

接下来,我尝试通过运行在该模块中执行一个类:

java -mp test -m de.mypackage/de.mypackage.Test

导致以下异常:

Error occurred during initialization of VM
java.lang.module.ResolutionException: JMOD files not supported: test/samples.jmod
at java.lang.module.Resolver.findWithBeforeFinder(java.base@9-ea/Resolver.java:729)
at java.lang.module.Resolver.resolveRequires(java.base@9-ea/Resolver.java:86)
at java.lang.module.Configuration.resolveRequiresAndUses(java.base@9-ea/Configuration.java:370)
at java.lang.module.ModuleDescriptor$1.resolveRequiresAndUses(java.base@9-ea/ModuleDescriptor.java:1986)
at jdk.internal.module.ModuleBootstrap.boot(java.base@9-ea/ModuleBootstrap.java:263)
at java.lang.System.initPhase2(java.base@9-ea/System.java:1928)

如果我只是将我的 classes 目录(我用来创建 JMOD 文件的目录)设置为模块路径,一切都会按预期工作。

JMOD 文件一般不可能放在模块路径上吗?如果是这样,有什么理由吗?

最佳答案

参见 http://openjdk.java.net/jeps/261#Packaging:-JMOD-files

JMOD files can be used at compile time and link time, but not at run time. To support them at run time would require, in general, that we be prepared to extract and link native-code libraries on-the-fly. This is feasible on most platforms, though it can be very tricky, and we have not seen many use cases that require this capability, so for simplicity we have chosen to limit the utility of JMOD files in this release.

关于java - 使用 Java 9 将自定义 JMOD 添加到模块路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38267059/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com