使用Java 9将自定义JMOD添加到模块路径 [英] Add a custom JMOD to the module path with Java 9

查看:445
本文介绍了使用Java 9将自定义JMOD添加到模块路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I created a simple JMOD file with the jmod tool like this

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

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

Next, I tried to execute a class within that module by running:

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)

如果我只设置我的目录(我曾经创建过)作为模块路径的JMOD文件),一切都按预期工作。

If I just set my classes directory (that I used to create the JMOD file) as modulepath, everything is working as expected.

通常不可能有 JMOD 文件在模块路径?如果是这种情况,有什么理由吗?

Is it generally not possible to have JMOD files on the modulepath? And if this is the case, is there any reason for that?

推荐答案

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


JMOD文件可以在编译时和链接时使用,但不能在运行
时使用。一般来说,要在运行时支持它们,我们需要准备好b $ b b来实时提取和链接本机代码库。这个
在大多数平台上是可行的,虽然它可能非常棘手,而我们
还没有看到很多需要这种功能的用例,所以对于
简单性我们选择限制实用性这个
版本中的JMOD文件。

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 9将自定义JMOD添加到模块路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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