Skip to content
Permalink
Browse files

Added tasks for JDK's jmod and jlink tools.

  • Loading branch information
VGR authored and bodewig committed Dec 7, 2018
1 parent 7b29e8f commit 343dff90f2a06a14a5e3d8f787de87d4446af3d9
@@ -42,6 +42,7 @@
<property name="ant.package" value="org/apache/tools/ant"/>
<property name="taskdefs.package" value="${ant.package}/taskdefs"/>
<property name="condition.package" value="${taskdefs.package}/condition"/>
<property name="modules.package" value="${taskdefs.package}/modules"/>
<property name="optional.package" value="${taskdefs.package}/optional"/>
<property name="type.package" value="${ant.package}/types"/>
<property name="optional.type.package" value="${type.package}/optional"/>
@@ -178,6 +179,10 @@
===================================================================
-->

<selector id="needs.jdk9+">
<filename name="${modules.package}/"/>
</selector>

<!-- Kaffe has some JDK 1.5 features including java.lang.Readable,
but not all of them -->
<selector id="not.in.kaffe">
@@ -609,6 +614,7 @@
<selector id="conditional-patterns">
<not>
<or>
<selector refid="needs.jdk9+" unless="jdk9+"/>
<selector refid="not.in.kaffe" if="kaffe"/>
<selector refid="needs.apache-resolver" unless="apache.resolver.present"/>
<selector refid="needs.junit" unless="junit.present"/> <!-- TODO should perhaps use -source 1.4? -->
@@ -26,9 +26,14 @@ <h3><em><u>Deprecated</u></em></h3>
<p><em>This task has been <u>deprecated</u>. Use a <a href="../Types/zipfileset.html">zipfileset</a>
or <a href="../Tasks/zip.html#zipgroupfileset">zipgroupfileset</a> with
the <a href="../Tasks/jar.html">Jar task</a> or <a href="../Tasks/zip.html">Zip task</a>
instead.</em></p>
instead. For a task based on the JDK's jlink tool, see
<a href="link.html">Link</a>.</em></p>

<h3>Description</h3>
<p><strong>For a task based on the JDK's jlink tool, see
<a href="link.html">Link</a>. This task is for something else
entirely.</strong></p>

<p>Links entries from sub-builds and libraries.</p>

<p>The <code>jlink</code> task can be used to build jar and zip files, similar to
@@ -0,0 +1,330 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
<title>Jmod Task</title>
</head>

<body>

<h2 id="jmod">Jmod</h2>
<h3>Description</h3>
<p>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
<a href="https://docs.oracle.com/en/java/javase/11/tools/jmod.html">jmod</a>
tool.</p>
<p>Requires Java 9 or later.</p>

<h3>Parameters</h3>
<table class="attr">
<tr>
<th scope="col">Attribute</th>
<th scope="col">Description</th>
<th scope="col">Required</th>
</tr>
<tr>
<td>destFile</td>
<td>jmod file to create.</td>
<td>Yes</td>
</tr>
<tr>
<td>classpath</td>
<td>Files to be placed in the jmod file. Usually a single module.</td>
<td rowspan="2">One of these is required, unless a nested
<code>&lt;classpath&gt;</code> is present.</td>
</tr>
<tr>
<td>classpathref</td>
<td class="left">Files to be placed in the jmod file, given as a
<a href="../using.html#references">reference</a>
to a path defined elsewhere.</td>
</tr>
<tr>
<td>modulepath</td>
<td>Locations of modules on which classpath modules depend.</td>
<td>No</td>
</tr>
<tr>
<td>modulepathref</td>
<td>Locations of modules on which classpath modules depend,
given as a <a href="../using.html#references">reference</a>
to a path defined elsewhere.</td>
<td>No</td>
</tr>
<tr>
<td>commandpath</td>
<td>Directories containing native commands to include in jmod.</td>
<td>No</td>
</tr>
<tr>
<td>commandpathref</td>
<td>Directories containing native commands to include in jmod,
given as a <a href="../using.html#references">reference</a>
to a path defined elsewhere.</td>
<td>No</td>
</tr>
<tr>
<td>headerpath</td>
<td>Directories containing header files to include in jmod.</td>
<td>No</td>
</tr>
<tr>
<td>headerpathref</td>
<td>Directories containing header files to include in jmod,
given as a <a href="../using.html#references">reference</a>
to a path defined elsewhere.</td>
<td>No</td>
</tr>
<tr>
<td>configpath</td>
<td>Directories containing user-editable configuration files
to include in jmod.</td>
<td>No</td>
</tr>
<tr>
<td>configpathref</td>
<td>Directories containing user-editable configuration files
to include in jmod,
given as a <a href="../using.html#references">reference</a>
to a path defined elsewhere.</td>
<td>No</td>
</tr>
<tr>
<td>legalpath</td>
<td>Directories containing legal licenses and notices to include in jmod.</td>
<td>No</td>
</tr>
<tr>
<td>legalpathref</td>
<td>Directories containing legal licenses and notices to include in jmod,
given as a <a href="../using.html#references">reference</a>
to a path defined elsewhere.</td>
<td>No</td>
</tr>
<tr>
<td>nativelibpath</td>
<td>Directories containing native libraries to include in jmod.</td>
<td>No</td>
</tr>
<tr>
<td>nativelibpathref</td>
<td>Directories containing native libraries to include in jmod,
given as a <a href="../using.html#references">reference</a>
to a path defined elsewhere.</td>
<td>No</td>
</tr>
<tr>
<td>manpath</td>
<td>Directories containing man pages to include in jmod.</td>
<td>No</td>
</tr>
<tr>
<td>manpathref</td>
<td>Directories containing man pages to include in jmod,
given as a <a href="../using.html#references">reference</a>
to a path defined elsewhere.</td>
<td>No</td>
</tr>
<tr>
<td>version</td>
<td><a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/module/ModuleDescriptor.Version.html">Module version</a> of jmod.</td>
<td>No</td>
</tr>
<tr>
<td>mainclass</td>
<td>Class that acts as executable entry point of module.</td>
<td>No</td>
</tr>
<tr>
<td>platform</td>
<td>The target platform for the jmod. Typically takes the form
<var>OS</var><code>-</code><var>architecture</var>. A particular JDK's
platform can be seen by running a command like
<samp>jmod describe $JDK_HOME/jmods/java.base.jmod | grep -i platform</samp></td>
<td>No</td>
</tr>
<tr>
<td>hashModulesPattern</td>
<td>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.</td>
<td>No</td>
</tr>
<tr>
<td>resolveByDefault</td>
<td>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.</td>
<td>No. Default is true.</td>
</tr>
<tr>
<td>moduleWarnings</td>
<td>Whether to emit warnings when resolving modules which are
not recommended for use. Comma-separated list of one of more of
the following:
<dl>
<dt><code>deprecated</code></dt>
<dd>Warn if module is deprecated</dd>
<dt><code>leaving</code></dt>
<dd>Warn if module is deprecated for removal</dd>
<dt><code>incubating</code></dt>
<dd>Warn if module is an incubating (not yet official) module</dd>
</dl>
</td>
<td>No, default is no warnings.</td>
</tr>
</table>

<h3>Parameters specified as nested elements</h3>
<h4>classpath, modulepath, commandpath, headerpath, configpath, legalpath, nativelibpath, manpath</h4>
<p>The
<code>classpath</code>,
<code>modulepath</code>,
<code>commandpath</code>,
<code>headerpath</code>,
<code>configpath</code>,
<code>legalpath</code>,
<code>nativelibpath</code>, and
<code>manpath</code>
attributes are <a href="../using.html#path">path-like structures</a>
and can also be set via nested
<code>&lt;classpath&gt;</code>,
<code>&lt;modulepath&gt;</code>,
<code>&lt;commandpath&gt;</code>,
<code>&lt;headerpath&gt;</code>,
<code>&lt;configpath&gt;</code>,
<code>&lt;legalpath&gt;</code>,
<code>&lt;nativelibpath&gt;</code>, and
<code>&lt;manpath&gt;</code>
elements, respectively.</p>

<h4>version</h4>
<p>Fine-grained alternative to the <code>version</code> attribute. This
nested element has these attributes:</p>
<table class="attr">
<tr>
<th scope="col">Attribute</th>
<th scope="col">Description</th>
<th scope="col">Required</th>
</tr>
<tr>
<td>number</td>
<td>Primary version number. Can be any text, as long as it does not
contain a hyphen (<code>-</code>) or plus (<code>+</code>).</td>
<td>Yes</td>
</tr>
<tr>
<td>preRelease</td>
<td>Pre-release version. Can be any text, as long as it does not
contain a plus (<code>+</code>).</td>
<td>No</td>
</tr>
<tr>
<td>build</td>
<td>Build version. Can be any text.
<td>No</td>
</tr>
</table>

<p>See the <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/module/ModuleDescriptor.Version.html">ModuleDescriptor.Version documentation</a>
for a full description of the meaning of each version component.</p>

<h4>moduleWarning</h4>
<p>Like the <code>moduleWarnings</code> 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.</p>

<p>Attributes:</p>
<table class="attr">
<tr>
<th scope="col">Attribute</th>
<th scope="col">Description</th>
<th scope="col">Required</th>
</tr>
<tr>
<td>reason</td>
<td>Condition which will cause jmod tool to emit warnings. One of:
<dl>
<dt><code>deprecated</code></dt>
<dd>Warn if module is deprecated</dd>
<dt><code>leaving</code></dt>
<dd>Warn if module is deprecated for removal</dd>
<dt><code>incubating</code></dt>
<dd>Warn if module is an incubating (not yet official) module</dd>
</dl>
<td>Yes</td>
</tr>
</table>

<h3>Examples</h3>

<h4>Basic jmod</h4>
<p>Create a jmod from a single modular jar file:</p>
<pre>
&lt;jmod destfile="MyApp.jmod" classpath="build/myapp.jar"/&gt;
</pre>

<h4>With dependencies</h4>
<p>Create a jmod from a modular jar file which depends on another module:</p>
<pre>
&lt;jmod destfile="MyApp.jmod" classpath="build/myapp.jar"&gt;
&lt;modulepath&gt;
&lt;pathelement location="libs/thirdpartyutils.jar"/&gt;
&lt;/modulepath&gt;
&lt;/jmod&gt;
</pre>

<h4>With version</h4>
<p>Create a jmod with a module version:</p>
<pre>
&lt;jmod destfile="MyApp.jmod" classpath="build/myapp.jar"
version="1.2.1-ea+29"/&gt;
</pre>

<p>Create a versioned jmod from module version components:</p>
<pre>
&lt;property name="version" value="1.2.1"/&gt;
&lt;buildnumber/&gt;
&lt;loadfile property="buildnum" srcFile="build.number"/&gt;
&lt;jmod destfile="MyApp.jmod" classpath="build/myapp.jar"&gt;
&lt;version number="${version}" build="${buildnum}"/&gt;
&lt;/jmod&gt;
</pre>

<h4>Main class</h4>
<p>Create a jmod with a main class:</p>
<pre>
&lt;jmod destfile="MyApp.jmod" classpath="build/myapp.jar"
mainclass="com.example.myapp.MainWindow"/&gt;
</pre>

<h4>Target platform</h4>
<p>Create a jmod for a specific platform, possibly different from the
current platform:</p>

<pre>
&lt;jmod destfile="MyApp.jmod" classpath="build/myapp.jar"
platform="windows-amd64"/&gt;
</pre>

</body>
</html>

6 comments on commit 343dff9

@twogee

This comment has been minimized.

Copy link
Contributor

twogee replied Dec 15, 2018

src/etc/poms/ant/pom.xml should exclude the new tasks from compilation; Maven builds are Java 8 only.

@craigpell

This comment has been minimized.

Copy link

craigpell replied Dec 15, 2018

It appears I can just add <exclude>org/apache/tools/ant/taskdefs/modules/</exclude> to the excludes and testExcludes elements to do that, correct? (I don't particularly want to install Maven, but if I need to in order to test this, I will.)

@twogee

This comment has been minimized.

Copy link
Contributor

twogee replied Dec 15, 2018

Yes, that's the idea.

@bodewig

This comment has been minimized.

Copy link
Member

bodewig replied Dec 16, 2018

I'll take care of it.

@twogee

This comment has been minimized.

Copy link
Contributor

twogee replied Dec 16, 2018

Thanks, perhaps it's time for multi-release jars?

@bodewig

This comment has been minimized.

Copy link
Member

bodewig replied Dec 16, 2018

fixed with 876376a - many thanks for catching this @twogee

Please sign in to comment.
You can’t perform that action at this time.