Netbeans - Single JAR

By qless on Sunday 30 May 2010 21:26 - Comments (6)
Categories: Java, Programming, Tutorial, Views: 5.111

Netbeans is one of the free great Java IDE's, but its default build creates a dist folder with a small jar and a subfolder with the libraries.
In eclipse I had a plugin called "fat-jar" which would build one big jar. In Netbeans this is possible with a small piece of xml config in the build.xml: (add at the end, before the closing project tag)

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<target name="package-for-store" depends="jar">

        <!-- Change the value of this property to be the name of your JAR,
             minus the .jar extension. It should not have spaces.
             <property name="store.jar.name" value="MyJarName"/>
        -->
        <property name="store.jar.name" value="VDSL2tool"/>


        <!-- don't edit below this line -->

        <property name="store.dir" value="store"/>
        <property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>

        <echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>

        <delete dir="${store.dir}"/>
        <mkdir dir="${store.dir}"/>

        <jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
            <zipgroupfileset dir="dist" includes="*.jar"/>
            <zipgroupfileset dir="dist/lib" includes="*.jar"/>

            <manifest>
                <attribute name="Main-Class" value="${main.class}"/>
            </manifest>
        </jar>

        <zip destfile="${store.jar}">
            <zipfileset src="${store.dir}/temp_final.jar"
            excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
        </zip>

        <delete file="${store.dir}/temp_final.jar"/>

    </target>


Now after your development, testing you can build a single, executable, jar file, by right mouse clicking on the build.xml file and selecting the proper target:
netbeans build single jar

Next step would be building the windows exe and mac app bundle from this executable jar.

Volgende: Single JAR - .exe & mac app 06-'10 Single JAR - .exe & mac app
Volgende: VDSL2 modem data - 7 05-'10 VDSL2 modem data - 7

Comments


By Tweakers user woutertje, Sunday 30 May 2010 21:48

The most recent version of eclipse has the "fat-jar" plugin built in, it's called "Runnable Jar".
I'm interested to know why you prefer Netbeans over Eclipse?

By Bram, Monday 31 May 2010 09:22

Which tool do you use to build .exe-files from .jar-files?

By Tweakers user qless, Monday 31 May 2010 09:46

woutertje wrote on Sunday 30 May 2010 @ 21:48:
The most recent version of eclipse has the "fat-jar" plugin built in, it's called "Runnable Jar".
I'm interested to know why you prefer Netbeans over Eclipse?
At this moment 2 main reasons-
- JavaFX support (more up-to-date then eclipse)
- GUI building

I liked Eclipse too, just use the one you think is best (Just avoid JBuilder....)
Bram wrote on Monday 31 May 2010 @ 09:22:
Which tool do you use to build .exe-files from .jar-files?
My next post I'll give an example of exe and mac app versions of a jar.

[Comment edited on Monday 31 May 2010 09:47]


By Abdul Mohsin, Tuesday 26 October 2010 13:40

Thanks for the post , I have tried it and it worked.

Thanks,
Abdul Mohsin

By Per Eriksson, Thursday 10 March 2011 12:54

Thank you!
You are a champion!!!

/Per

By Michael Wallace, Sunday 23 September 2012 13:48

Perfect example!
Thanks very much.

Comment form
(required)
(required, but will not be displayed)
(optional)

Please enter the code from the image below: