Main class in jar

Alan Bateman Alan.Bateman at oracle.com
Mon Mar 5 11:05:22 UTC 2018


On 05/03/2018 10:43, Bernard Amade wrote:
> thanks for your help
>
> just curious about this internal information:
>
> ---------------------------------------------------
> "ModuleMainClass" attribute. Note that this is a class file attribute, not an attribute that you put in the main manifest of a JAR file. The `jar` tool will add both when you specify the main class with `--main-class` or `-e`.
>>   The app module must have a ModuleMainClass class file attribute, something the `jar` tool will do for you
> ----------------------------------
> where does this "ModuleMainClass" attribute lies internally?
> (I've tried to decompile almost every file but have not found it)
It's an attribute in the module-info.class. You can use `javap` to see 
all the details if you want, e.g.
   javap --module-path app.jar -m app -v module-info

The `jar` tool might be easier for your audience, e.g.
   jar --file=app.jar --describe-module


> :
>
> PS: if I understand things correctly the reason for not having an autonomous jar (like in java -jar) is that
> starting a modular application from jars needs a lot of specific command-line options ....
> Do we really have to stick to shell scripts to start an app? (when we do not go for a jlink generated image)
If the initial module is not in the run-time image then you have to 
specify the module path so that the module can be found. Re-purposing 
`java -jar` was discussed here but for the initial release at least, 
`java -jar ...` will put the JAR file on the class path as it has always 
done. It's also related to the #MultiModuleExecutableJARs issue where 
there is interest in packaging an initial module, along transitive 
dependences, in a single JAR file. So I expect this area will be 
revisited at some point.

-Alan


More information about the jigsaw-dev mailing list