ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [2/2] ant git commit: simple way of creating a JEP-238 multi release jar
Date Wed, 21 Sep 2016 12:01:42 GMT
simple way of creating a JEP-238 multi release jar


Branch: refs/heads/master
Commit: 6b17b4cf69c77a1e100947b259c2171031522313
Parents: af3d90c
Author: Jan Matèrne <>
Authored: Wed Sep 21 10:00:20 2016 +0200
Committer: Jan Matèrne <>
Committed: Wed Sep 21 10:00:20 2016 +0200

 manual/Tasks/jar.html                   | 35 ++++++++++++++++++++++++++++
 src/tests/antunit/taskdefs/jar-test.xml |  8 ++++++-
 2 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/manual/Tasks/jar.html b/manual/Tasks/jar.html
index 1df2ee0..6920eff 100644
--- a/manual/Tasks/jar.html
+++ b/manual/Tasks/jar.html
@@ -90,6 +90,11 @@ to a value other than its default, <code>"add"</code>.</b></p>
 <p>To cryptographically sign your JAR file, use the <a href="signjar.html">SignJar
task</a> on the JAR that you create from this task.</p>
+<p>For creating a simple version of a <a target="_blank" href="">JEP-238
multi release jar</a>,
+you don't need any special tools. Just set the required manifest entry and place the files
where required, as you could see 
+in the <a href="#jep238-example">JEP238-example</a>. If you want to tune this
kind of jar, e.g. decreasing the size by deleting 
+'same' classes from the versions-branches, you have to do more ...</p> 
 <table border="1" cellpadding="2" cellspacing="0">
@@ -583,6 +588,36 @@ Sealed: false</code></pre></blockquote>
+<a name="jep238-example"/>
+<h4>JEP238 example: a Multi-Release JAR Files</h4>
+  Here we want to create a <i>Multi-Release JAR File</i> according the specification
+  <a target="_blank" href="">JEP-238</a>.
+  It defines on top of a JAR the possibility to place additional or overwriting classes 
+  in a jar, which are available according to the Java version you run.<br> 
+  Basically it sais, that you have to set the manifest entry <tt>Multi-Release: true</tt>

+  and place all additional or overwriting classes in 
+  <tt>META-INF/versions/<i>number</i>/package-structure</tt>, e.g.

+  <tt>META-INF/versions/9/org/apache/ant/MyClass.class</tt>
+  In this example we expect that the normal classes are compiled into
+  <code>${java.classes}</code> and the Java9 classes are compiled into 
+  <code>${java9.classes}</code>. 
+    &lt;jar destfile=&quot;mrjar.jar&quot;&gt;
+      &lt;manifest&gt;
+        &lt;!-- special mf-entry according to the spec --&gt;
+        &lt;attribute name=&quot;Multi-Release&quot; value=&quot;true&quot;/&gt;
+      &lt;/manifest&gt;
+      &lt;!-- directory structure according to the spec ... --&gt;
+      &lt;!-- ... default classes loadable by old (&lt;Java9) versions --&gt;
+      &lt;fileset dir=&quot;${java.classes}&quot;/&gt;
+      &lt;!-- ... per release classes, require Java9+ for loadable via standard ClassLoader
+      &lt;zipfileset prefix=&quot;META-INF/versions/9/&quot; dir=&quot;${java9.classes}&quot;/&gt;
+    &lt;/jar&gt;
diff --git a/src/tests/antunit/taskdefs/jar-test.xml b/src/tests/antunit/taskdefs/jar-test.xml
index bd0026a..f1206ed 100644
--- a/src/tests/antunit/taskdefs/jar-test.xml
+++ b/src/tests/antunit/taskdefs/jar-test.xml
@@ -301,7 +301,13 @@ Main-Class: MyClass
-    <au:assertEquals expected="Java8" actual="${valueFrom8}"/>
+    <au:assertTrue>
+      <or>
+    	<equals arg1="Java8" arg2="${valueFrom8}"/>
+        <!-- maybe we are running on an early version of Java9 -->
+    	<equals arg1="Java9" arg2="${valueFrom8}"/>
+      </or>
+    </au:assertTrue>
       <zipentry zipfile="${antunit.tmpdir}/mrjar.jar" name="META-INF/versions/9/org/apache/ant/test/MRJarTest.class"/>

View raw message