Starting a module with main class from a different module

Tomas Langer tomas.langer at oracle.com
Thu Jan 25 12:34:42 UTC 2024


Is there a way to define a main class on a module if it comes from a different one?

Currently we need to start the JVM as follows:
java –module-path ... --add-modules my.modular.application --module io.helidon.microprofile.cdi/io.helidon.microprofile.cdi.Main

What we do:

  *   our microprofile implementation bootstraps a framework, that discovers its component using service loader, it also contains the Main class needed to start
  *   the "my.modular.application" provides such components (such as an HTTP endpoint), but does not need a main class

Ideally, I would like to run "my.modular.application" to have a simpler command line.
I cannot do that, as the main class is from a different module (and I think that cannot be added to the module metadata).
So I have to run the main class from the CDI module, and use `--add-modules`, as otherwise my application module would not end up on the module path (as it is not the "main" module started).


Is there some way please to simplify this? Or do we need to create a Main class for each application, even if it would just delegate to the "cdi.Main"?

When running on classpath, there is no problem, as the `Main-Class` attribute in manifest can point to a class in another jar, and the `Class-Path` attribute in the manifest can contain the jar that has the main class, so on classpath we can do:
java -jar my.modular.application.jar

Thanks
Tomas Langer
project Helidon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jigsaw-dev/attachments/20240125/626f18aa/attachment.htm>


More information about the jigsaw-dev mailing list