Dominic Charley-Roy
https://github.com/dominiccharleyroy
dominic.charley-roy @ mail.mcgill


Step 1. From Eclipse: go to the File menu and hit Export. Select Runnable Jar File


Hit the Finish button!

You might get a message about repacking referenced libraries... don't worry about that for now!

MyClassName.class.getResource("/download.jpg")

sudo apt-get install ant
ant taskNameHere we will create a build.xml file with one task (hello-world) which is the default task. When invoke, it simply prints out "Hello, world!"
<project name="MyProject" default="hello-world" basedir=".">
<target name="hello-world">
<echo>Hello, world!</echo>
</target>
</project>$ ant hello-world
Buildfile: /home/dom/Coding/Workspace/AntJarExample/build.xml
hello-world:
[echo] Hello, world!
BUILD SUCCESSFUL
Total time: 0 seconds<property name="src" location="src"/>
<property name="build" location="bin"/>
<property name="dist" location="dist"/>Our clean task should simply delete the bin and dist folders.
<project name="MyProject" default="compile" basedir=".">
<property name="src" location="src"/>
<property name="lib" location="lib"/>
<property name="res" location="res"/>
<property name="build" location="bin"/>
<property name="dist" location="dist"/>
<target name="clean">
<!--
Delete our directories.
-->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
...
</project>This compiles all of our files in the source folder and puts them as .class files in the bin folder. Note that it cleans first!
<target name="compile" depends="clean">
<!-- Create the build directory. -->
<mkdir dir="${build}"/>
<!--
Compile all of the source files.
Make sure to include libraries.
-->
<javac srcdir="${src}" destdir="${build}">
<classpath>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
<!-- Copy our resources. -->
<copy todir="${build}">
<fileset dir="${res}"/>
</copy>
</target>This creates the Jar file and puts it in the dist folder!
Note: This can be automatically generated from Eclipse in the Export to Runnable Jar screen.
<target name="jar" depends="compile">
<!-- Create our dist folder. -->
<mkdir dir="${dist}"/>
<!-- Create the jar file as build.jar -->
<jar destfile="${dist}/build.jar" filesetmanifest="mergewithoutmain">
<!-- Specify the class which has the main method. -->
<manifest>
<attribute name="Main-Class" value="TestApp"/>
<attribute name="Class-Path" value="."/>
</manifest>
<!-- Add in our compiled files. -->
<fileset dir="${build}"/>
<!-- Add in our libraries. -->
<zipgroupfileset dir="${lib}" includes="**/*.jar"/>
</jar>
</target>$ ant jar
Buildfile: /home/dom/Coding/Workspace/AntJarExample/build.xml
clean:
[delete] Deleting directory /home/dom/Coding/Workspace/AntJarExample/bin
[delete] Deleting directory /home/dom/Coding/Workspace/AntJarExample/dist
compile:
[mkdir] Created dir: /home/dom/Coding/Workspace/AntJarExample/bin
[javac] Compiling 2 source files to /home/dom/Coding/Workspace/AntJarExample/bin
[copy] Copying 1 file to /home/dom/Coding/Workspace/AntJarExample/bin
jar:
[mkdir] Created dir: /home/dom/Coding/Workspace/AntJarExample/dist
[jar] Building jar: /home/dom/Coding/Workspace/AntJarExample/dist/build.jar
BUILD SUCCESSFUL
Total time: 1 second
We can create an Ant target to generate the HTML version of our Javadoc! This will put our HTML files in the doc folder.
Just make sure to add the right line to clean.
<property name="doc" location="doc"/>
...
<target name="doc" depends="clean">
<!-- Create the doc directory. -->
<mkdir dir="${doc}"/>
<!-- Generate the Javadoc. -->
<javadoc sourcepath="${src}" destdir="${doc}"/>
</target>