ModuleMainClass attribute via module-info.java
Remi Forax
forax at univ-mlv.fr
Sun May 31 21:35:05 UTC 2020
----- Mail original -----
> De: "Florian Weimer" <fw at deneb.enyo.de>
> À: "jigsaw-dev" <jigsaw-dev at openjdk.java.net>
> Envoyé: Dimanche 31 Mai 2020 19:31:48
> Objet: ModuleMainClass attribute via module-info.java
> Is it possible to instruct javac to generate a ModuleMainClass
> attribute via a module declaration? I can't find the appropriate
> syntax in the JLS. If there is no way to get javac to generate the
> attribute, what is the reason for that?
Hi Florian,
the design of JPMS separates what is useful for Java described by the module-info.java (required modules, exported or open packages, etc) and what is metadata for distribution (module version, module main, modules hashes, etc) stored as supplementary attributes (or optional fields of the Module attribute) in the module-info.class.
Changing the main class or the version of a module do not require a recompilation, so those information are not handled by javac but injected into the module-info.class by jar, because those information are useful only when you want to create a jar in order to distribute it.
We came to that design to be able to support already existing ways of packaging the metadata associated with a jar file so a jar can be at the same time a module for JPMS and also a module for Jboss module or an OSGI bundle, etc. As an example of metadata fusion, you can use a tool like bnd [1], a tool developed originally to package OSGI bundles, if you want to use a Java annotation to specify the main class.
regards,
Rémi
[1] https://bnd.bndtools.org/chapters/330-jpms.html
More information about the jigsaw-dev
mailing list