Jmod

Since Apache Ant 1.10.6

Description

Creates a linkable jmod file from a modular jar file, and optionally from other application files such as native libraries and license documents. Equivalent to the JDK's jmod tool.

Requires Java 9 or later.

Parameters

Attribute Description Required
destFile jmod file to create. Yes
classpath Files to be placed in the jmod file. Usually a single module. One of these is required, unless a nested <classpath> is present.
classpathref Files to be placed in the jmod file, given as a reference to a path defined elsewhere.
modulepath Locations of modules on which classpath modules depend. No
modulepathref Locations of modules on which classpath modules depend, given as a reference to a path defined elsewhere. No
commandpath Directories containing native commands to include in jmod. No
commandpathref Directories containing native commands to include in jmod, given as a reference to a path defined elsewhere. No
headerpath Directories containing header files to include in jmod. No
headerpathref Directories containing header files to include in jmod, given as a reference to a path defined elsewhere. No
configpath Directories containing user-editable configuration files to include in jmod. No
configpathref Directories containing user-editable configuration files to include in jmod, given as a reference to a path defined elsewhere. No
legalpath Directories containing legal licenses and notices to include in jmod. No
legalpathref Directories containing legal licenses and notices to include in jmod, given as a reference to a path defined elsewhere. No
nativelibpath Directories containing native libraries to include in jmod. No
nativelibpathref Directories containing native libraries to include in jmod, given as a reference to a path defined elsewhere. No
manpath Directories containing man pages to include in jmod. No
manpathref Directories containing man pages to include in jmod, given as a reference to a path defined elsewhere. No
version Module version of jmod. No
mainclass Class that acts as executable entry point of module. No
platform The target platform for the jmod. Typically takes the form OS-architecture. A particular JDK's platform can be seen by running a command like jmod describe $JDK_HOME/jmods/java.base.jmod | grep -i platform No
hashModulesPattern Regular expression for names of modules in the module path which depend on the jmod being created, and which should have hashes generated for them and included in the new jmod. No
resolveByDefault Boolean indicating whether the jmod should be one of the default resolved modules when it is in a module path searched by tools and applications. No. Default is true.
moduleWarnings Whether to emit warnings when resolving modules which are not recommended for use. Comma-separated list of one of more of the following:
deprecated
Warn if module is deprecated
leaving
Warn if module is deprecated for removal
incubating
Warn if module is an incubating (not yet official) module
No, default is no warnings.

Parameters specified as nested elements

classpath, modulepath, commandpath, headerpath, configpath, legalpath, nativelibpath, manpath

The classpath, modulepath, commandpath, headerpath, configpath, legalpath, nativelibpath, and manpath attributes are path-like structures and can also be set via nested <classpath>, <modulepath>, <commandpath>, <headerpath>, <configpath>, <legalpath>, <nativelibpath>, and <manpath> elements, respectively.

version

Fine-grained alternative to the version attribute. This nested element has these attributes:

Attribute Description Required
number Primary version number. Can be any text, as long as it does not contain a hyphen (-) or plus (+). Yes
preRelease Pre-release version. Can be any text, as long as it does not contain a plus (+). No
build Build version. Can be any text. No

See the ModuleDescriptor.Version documentation for a full description of the meaning of each version component.

moduleWarning

Like the moduleWarnings attribute, but only specifies a single basis for emitting warnings. This child element may appear multiple times, to specify multiple conditions under which warnings should be emitted by the jmod tool.

Attributes:

Attribute Description Required
reason Condition which will cause jmod tool to emit warnings. One of:
deprecated
Warn if module is deprecated
leaving
Warn if module is deprecated for removal
incubating
Warn if module is an incubating (not yet official) module
Yes

Examples

Basic jmod

Create a jmod from a single modular jar file:

<jmod destfile="MyApp.jmod" classpath="build/myapp.jar"/>

With dependencies

Create a jmod from a modular jar file which depends on another module:

<jmod destfile="MyApp.jmod" classpath="build/myapp.jar">
    <modulepath>
        <pathelement location="libs/thirdpartyutils.jar"/>
    </modulepath>
</jmod>

With version

Create a jmod with a module version:

<jmod destfile="MyApp.jmod" classpath="build/myapp.jar"
      version="1.2.1-ea+29"/>

Create a versioned jmod from module version components:

<property name="version" value="1.2.1"/>
<buildnumber/>
<loadfile property="buildnum" srcFile="build.number"/>
<jmod destfile="MyApp.jmod" classpath="build/myapp.jar">
    <version number="${version}" build="${buildnum}"/>
</jmod>

Main class

Create a jmod with a main class:

<jmod destfile="MyApp.jmod" classpath="build/myapp.jar"
      mainclass="com.example.myapp.MainWindow"/>

Target platform

Create a jmod for a specific platform, possibly different from the current platform:

<jmod destfile="MyApp.jmod" classpath="build/myapp.jar"
      platform="windows-amd64"/>