Add custom JMOD to module path using Java 9

I created a simple JMOD file using a jmod tool like this

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

Next, I tried to execute the class inside this module by doing:

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

This led to the following exception:

 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) 

If I just set my classes directory (which I used to create the JMOD file) as a module, everything works as expected.

Is it usually impossible to have JMOD files on the module path? And if so, is there a reason for this?

+7
java java-9 jigsaw module-path
source share
1 answer

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

JMOD files can be used at compile time and link time, but not at startup time. To support them at runtime, it would be required, in general, for us to be prepared to extract and link native code libraries on the fly. This is possible on most platforms, although it can be very difficult, and we have not seen many use cases that require this feature, so for simplicity we decided to limit the usefulness of JMOD files in this release.

+3
source share

All Articles