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

前端之家收集整理的这篇文章主要介绍了使用Java 9将自定义JMOD添加到模块路径前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我用这样的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文件)设置为modulepath,那么一切都按预期工作.

通常不可能在模块路径上有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相关文章