Java - Using Eclipse to produce executable jar

Refer to Simplifying your deployment for other options.

Executable jar has the following limitation:

  • The customer's machine may not have appropriate JRE installed (consider packaging and distributing our software as a .exe file or whichever appropriate for our customers)

To use Eclipse to package our application which may involve multiple jar files / class files into a single executable jar, use the following in our build.xml:

<project name="svntool"  default="deploy"  basedir=".">
    <!-- set global properties for this build -->
    <property file=""/>
    <property name="src" value="../src" />
    <property name="bin" value="../bin" />
    <property name="dist" value="../.." />

    <path id="project.classpath">
        <fileset dir="C:\parsers\commons" casesensitive="no">
             <include name="commons-lang-2.4.jar"/>
        <fileset dir="C:\parsers\svnkit-1.7.4-v1\lib" casesensitive="no">
            <include name="svnkit-cli-1.7.4-v1.jar"/>
            <include name="svnkit-1.7.4-v1.jar"/>

    <target name="init">
        <!-- Create the dist directory structure used by compile and copy the deployment descriptors into it-->
            <format property="time_stamp" pattern="MM-dd-yyyy-hh-mm-aa"/>

        <mkdir dir="${bin}"/>

    <target name="clean">
        <!-- Sometimes you can clean with deleting the module file but it is best dealt on an as needed basis -->
        <delete dir="${bin}"/>

    <target name="compile" depends="init">
        <!-- Right Now, Fixing Target to 1.2 as Production is on 5.1 -->
        <javac optimize="yes" debug="yes" srcdir="${src}" nowarn="on" destdir="${bin}">
            <classpath refid="project.classpath" />

    <target name="deploy" depends="compile">
        <!-- create the executable jars -->
        <!-- Start of SVNTool -->
        <delete file="${dist}/BackgroundProcesses.jar"/>
        <delete dir="${dist}/empty"/>
        <mkdir dir="${dist}/empty"/>
        <jar destfile="${dist}/BackgroundProcesses.jar" basedir="${dist}/empty">
            <zipgroupfileset dir="C:\parsers\log4j" includes="log4j-1.2.14.jar"/>
            <zipgroupfileset dir="C:\parsers\svnkit-1.7.4-v1\lib" includes="svnkit-cli-1.7.4-v1.jar"/>
            <zipgroupfileset dir="C:\parsers\svnkit-1.7.4-v1\lib" includes="svnkit-1.7.4-v1.jar"/>
            <zipgroupfileset dir="C:\parsers\commons" includes="commons-lang-2.4.jar"/>
            <fileset dir="${bin}" includes="*.class"/>          
        <sleep seconds="1"/>
        <jar destfile="${dist}/svntool.jar" basedir="${dist}/empty">
                <attribute name="Main-Class" value="SVNTool"/>
            <zipfileset excludes="**/META-INF/**" src="${dist}/BackgroundProcesses.jar"/>
        <delete file="${dist}/BackgroundProcesses.jar"/>
        <delete dir="${dist}/empty"/>

Refer to Simplifying your deployment for other options.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License