Reputation: 707
I have a Java 8 application I am working on converting to Java 11 and of course with this I am working with the module system for the first time.
I have my application Maven assembly configuration set such that all the JAR files are put in a /lib directory of the bin distribution. The maven-jar-plugin then sets the MANIFEST Class-Path value with all the JAR file names. The application is run with a simple java -jar /lib/application.jar
Moving to Java 11, if I continue to build the bin distribution this way, I'm curious to know how the runtime interprets the MANIFEST Class-Path value? I read through the JAR specs (https://docs.oracle.com/en/java/javase/11/docs/specs/jar/jar.html) and I think I understand it as:
If I did want to change this, would I start putting any modular JAR file on the --module-path and keep the other JAR files on the Class-Path?
Upvotes: 2
Views: 3314
Reputation: 492
Exactly; Running via -jar all your code is in the unnamed module, while the JDK classes themselves are running on modules, that's why you can see "java.base/" in the stacktraces running with JDK 9+.
So your invocation would have to change from java -jar lib/application.jar
to java --module-path lib --module application/your.main.class
You can improve it further by using JLink and/or JPackage, where you can create an executable that already executes your module, like ./bin/application
.
Start by adding all jars to the module path and see if the Java doesn't say anything about split packages. So by doing that, it almost certain that your modules will be "automatic modules". So you can experience some ClassNotFoundException.
If that happens, you'll need to --add-module module
.
Upvotes: 3