Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 9 - Can I add the MainClass attribute to module-info.class in the archive? [duplicate]

In Java 9, you can create a JAR file with

jar --create --file=mlib/com.greetings.jar --main-class=com.greetings.Main -C mods/com.greetings .

Which has the side effect of adding the MainClass attribute to the module-info.class file in the .jar file.

Do any of the plugins support this yet, or do I need to invoke the Java 9 'jar' command directly?

Is this the right forum to be asking these questions, or is there a better place?

Cheers, Eric

like image 841
Eric Kolotyluk Avatar asked Jan 25 '17 21:01

Eric Kolotyluk


People also ask

Can a jar contain multiple modules?

It is that file that defines a module's name, dependencies, and APIs. So there is a strong connection between JARs and modules: JARs are the containers from which the module system creates modules and (at the moment) each JAR can only contain a single module.

What is modularity java9?

Java Module System is a major change in Java 9 version. Java added this feature to collect Java packages and code into a single unit called module. In earlier versions of Java, there was no concept of module to create modular Java applications, that why size of application increased and difficult to move around.

What is an unnamed module?

An unnamed module is a JAR that is built without module-info. java declaration. An unnamed module will require all other modules and will export all its packages as well. Type 2: Named Module. A named module is a module that is created with a module declaration file module-info.

What does transitive modifier mean?

The effect of the 'transitive' modifier is to cause additional modules to also depend on the other module. If module M 'requires transitive N', then not only does M depend on N, but any module that depends on M also depends on N.


1 Answers

The 'module main class' is actually an attribute of the module-info.class file. It's called ModuleMainClass and set by the Java 9's jar command. The current version (3.0.2) of maven-jar-plugin only writes the file when you specify the manifest.mainClass

like image 196
Machiel Avatar answered Oct 16 '22 08:10

Machiel