Bug 62772 - Update JAR Task to Specify --main-class Parameter
Summary: Update JAR Task to Specify --main-class Parameter
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.10.1
Hardware: PC All
: P2 enhancement with 1 vote (vote)
Target Milestone: ---
Assignee: Ant Notifications List
Depends on:
Reported: 2018-09-28 16:46 UTC by Jeff G
Modified: 2018-10-02 10:36 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
Description Jeff G 2018-09-28 16:46:29 UTC
In Java <=8, the main class within a JAR file was specified in the JAR manifest.  Specifying such a class using the JAR task has the following syntax:

    <jar destfile="something.jar" basedir="release/dir">
            <attribute name="Main-Class" value="fully.qualified.class.name" />

This appears to be implemented by passing the `-m [MANIFEST_FILE]` option to the JAR command (specifies a manifest file).  When creating modular JAR files in Java >=9, the only way to specify the ModuleMainClass attribute is to add the `-e fully.qualified.class.name` argument to the JAR command.

The current JAR task doesn't provide the capability to specify this command-line option, so I am forced to manually call the JAR command using the EXEC task instead.  Add functionality to supply a `-e` argument to the JAR command from the JAR task definition.
Comment 1 Stefan Bodewig 2018-10-02 05:27:46 UTC
Actually Ant does not use the command line jar tool at all, it creates the archive and the MANIFEST.MF inside of it all by itself.

So what needs to be changed in Ant is to mimic the effect of --main-class in the generated ZIP we call a jar. Without having looked into it in detail this likely means we need to tinker with the mudule-info.java file.
Comment 2 Jan Mat 2018-10-02 10:36:37 UTC
See also my comment to --module-version bug-entry

The content of the compiled module-info.class has to be changed.