JPMS / Jigsaw Missing main class in module

I am trying to create a modular executable jar that can be run using java -p <jar file> -m <module>on Java 9.0.1.

This works, as expected, when creating the flag with jar cfe test.jar test.Main -C classes/ ., but throws module test does not have a MainClass attribute, use -m <module>/<main-class>when generating with mvn packageand mvn assembly:single.

These maven generated jars still work with java -p test.jar -m test/test.Main, and all jars work along the class c path java -jar test.jar.


I looked at the contents of the container with jar xf test.jarand found that the jars are exactly the same, except for the manifest (see below):

Manifest-Version: 1.0
Created-By: 9.0.1 (Oracle Corporation)
Main-Class: test.Main

and

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: testuser
Build-Jdk: 9.0.1
Main-Class: test.Main

It is noteworthy that when specifying a working manifest you cannot use java -p test.jar -m test:

$ jar cfm test.jar test-contents/META-INF/MANIFEST.MF -C classes/ .
$ java -p test.jar -m test

module test does not have a MainClass attribute, use -m <module>/<main-class>

Edit : repo with expected behavior: https://github.com/deontologic/test

+4
1

jar tool , jmod tool .

--main-class class-name 

module-info.class.

JDK, mainClass ModuleDescriptor.mainClass().

--main-class .

, maven jar , .


, :

java -jar test-1.0.0-SNAPSHOT-jar-with-dependencies.jar

-jar, - JAR, . Main-Class (META-INF/MANIFEST.MF)

, :

java -p target/test-1.0.0-SNAPSHOT-jar-with-dependencies.jar -m test/test.Main
+4

Source: https://habr.com/ru/post/1691000/


All Articles