Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a custom JMOD to the module path with Java 9

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

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

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

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

Which resulted in 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 (that I used to create the JMOD file) as modulepath, everything is working as expected.

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

like image 481
Jan Gassen Avatar asked Jul 08 '16 12:07

Jan Gassen


People also ask

What is Module Path Java?

A CLASSPATH is a sequence of classes' base paths and JAR files for the Java Compiler or JVM to locate the classes used in the application. Similarly, in JDK 9, a MODULEPATH is a sequence of modules' base paths and Modular JAR files for the Java Compiler or JVM to locate the modules used in the application.

What are the main goals of Java 9?

The main goals for Java 9 are to: Make the Java Standard Edition platform, and the JDK, more navigable to scale down for small computing devices. Improve the overall security and maintain not only the JDK but the Java Implementations in general. Allow overall improved application performance.

What is a Java runtime image?

The JIMAGE is a special file format introduced with Java 9 to store custom runtime images. This file format is optimized for performance and storage. The file format basically acts as a container for JDK resources, classes, and modules, and indexes them for quick search and faster class loading.


1 Answers

See 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.

like image 69
Lagrang Avatar answered Sep 22 '22 20:09

Lagrang