Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Automatically Generate A .jar File In An Eclipse Java Project

I have an Eclipse Java project. It contains a folder named "dist". In that folder is a .jar file.

How can I set things up in this project to make sure this .jar file is updated any time one of the .java files in the project has been re-compiled?

Thanks.

like image 285
Dr. Faust Avatar asked Jul 13 '09 14:07

Dr. Faust


1 Answers

Create an Ant file and tell Eclipse to build it. There are only two steps and each is easy with the step-by-step instructions below.


Step 1 Create a build.xml file and add to package explorer:

<?xml version="1.0" ?> <!-- Configuration of the Ant build system to generate a Jar file -->  <project name="TestMain" default="CreateJar">   <target name="CreateJar" description="Create Jar file">         <jar jarfile="Test.jar" basedir="." includes="*.class" />   </target> </project> 

Eclipse should looks something like the screenshot below. Note the Ant icon on build.xml. Build.xml in Eclipse Project

Step 2 Right-click on the root node in the project. - Select Properties - Select Builders - Select New - Select Ant Build - In the Main tab, complete the path to the build.xml file in the bin folder.

Ant builder configurationBuild step - Targets Tab

Check the Output

The Eclipse output window (named Console) should show the following after a build:

Buildfile: /home/<user>/src/Test/build.xml  CreateJar:          [jar] Building jar: /home/<user>/src/Test/Test.jar BUILD SUCCESSFUL Total time: 152 milliseconds 
like image 116
Thomas Bratt Avatar answered Sep 23 '22 12:09

Thomas Bratt