You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by gmail Vladimir Koković <vl...@gmail.com> on 2020/03/26 18:37:57 UTC
Fat JAR for NetBeans
If one needs to distribute only one jar without dist/lib jars, the
following ant script segment should be inserted after the line <import
file = "nbproject/build-impl.xml" /> in the project build.xml:
<!--
This is original "Fat JARs out of NetBeans" for NetBeans 6.8 link:
https://busyprogrammer.wordpress.com/2010/01/26/fat-jars-out-of-netbeans/
For newer Netbeans it is necessary to change:
<target
depends="init,compile,-pre-pre-jar,-pre-jar,-unjar-and-copy-lib-jars"
name="fat-jar">
into
<target depends="-do-jar,-unjar-and-copy-lib-jars" name="fat-jar">
-->
<target name="-unjar-and-copy-lib-jars">
<!--
If the ant reports you a 'Cannot fix dependencies for:' message,
the following 2 lines allow you to overcome the jar problem
that is in the message:
<copy file="problematic.jar" todir="dist/lib" overwrite="true"/>
<echo level="info">Copied problematic.jar to dist/lib</echo>
-->
<unjar dest="${build.classes.dir}">
<fileset dir="dist/lib">
<include name="**/*.jar"/>
</fileset>
<patternset>
<exclude name="META-INF/**"/>
<exclude name="/*"/>
</patternset>
</unjar>
</target>
<target depends="-do-jar,-unjar-and-copy-lib-jars" name="fat-jar">
<property location="${build.classes.dir}"
name="build.classes.dir.resolved"/>
<jar destfile="${dist.jar}">
<fileset dir="${build.classes.dir}"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<echo>To run this application from the command line without Ant,
try:</echo>
<property location="${dist.jar}" name="dist.jar.resolved"/>
<echo>java -jar "${dist.jar.resolved}"</echo>
</target>
<target depends="clean,fat-jar" name="clean-and-fat-jar"/>
The inserted targets are called as follows:
Files-> build.xml-> Run Target-> Other Targets-> clean-and-fat-jar
or
Files-> build.xml-> Run Target-> Other Targets-> fat-jar
The result of these targets is dist/${dist.jar} and as mentioned above,
only that jar is distributed.
Vladimir Kokovic, DP senior (69)
Serbia, Belgrade, March 26, 2020
Re: Fat JAR for NetBeans
Posted by Geertjan Wielenga <ge...@apache.org>.
Nice. Sounds like a tip you might want to share on Twitter, etc, pointing
here. :-)
Gj
On Thu, Mar 26, 2020 at 7:38 PM gmail Vladimir Koković <
vladimir.kokovic@gmail.com> wrote:
> If one needs to distribute only one jar without dist/lib jars, the
> following ant script segment should be inserted after the line <import file
> = "nbproject/build-impl.xml" /> in the project build.xml:
>
> <!--
> This is original "Fat JARs out of NetBeans" for NetBeans 6.8 link:
>
> https://busyprogrammer.wordpress.com/2010/01/26/fat-jars-out-of-netbeans/
> For newer Netbeans it is necessary to change:
> <target
> depends="init,compile,-pre-pre-jar,-pre-jar,-unjar-and-copy-lib-jars"
> name="fat-jar">
> into
> <target depends="-do-jar,-unjar-and-copy-lib-jars" name="fat-jar">
> -->
> <target name="-unjar-and-copy-lib-jars">
> <!--
> If the ant reports you a 'Cannot fix dependencies for:' message,
> the following 2 lines allow you to overcome the jar problem that
> is in the message:
> <copy file="problematic.jar" todir="dist/lib" overwrite="true"/>
> <echo level="info">Copied problematic.jar to dist/lib</echo>
> -->
> <unjar dest="${build.classes.dir}">
> <fileset dir="dist/lib">
> <include name="**/*.jar"/>
> </fileset>
> <patternset>
> <exclude name="META-INF/**"/>
> <exclude name="/*"/>
> </patternset>
> </unjar>
> </target>
> <target depends="-do-jar,-unjar-and-copy-lib-jars" name="fat-jar">
> <property location="${build.classes.dir}"
> name="build.classes.dir.resolved"/>
> <jar destfile="${dist.jar}">
> <fileset dir="${build.classes.dir}"/>
> <manifest>
> <attribute name="Main-Class" value="${main.class}"/>
> </manifest>
> </jar>
> <echo>To run this application from the command line without Ant,
> try:</echo>
> <property location="${dist.jar}" name="dist.jar.resolved"/>
> <echo>java -jar "${dist.jar.resolved}"</echo>
> </target>
> <target depends="clean,fat-jar" name="clean-and-fat-jar"/>
>
>
> The inserted targets are called as follows:
> Files-> build.xml-> Run Target-> Other Targets-> clean-and-fat-jar
> or
> Files-> build.xml-> Run Target-> Other Targets-> fat-jar
>
> The result of these targets is dist/${dist.jar} and as mentioned above,
> only that jar is distributed.
>
> Vladimir Kokovic, DP senior (69)
> Serbia, Belgrade, March 26, 2020
>