[ACCEPTED]-Build project into a JAR automatically in Eclipse-jar
You want a .jardesc
file. They do not kick off automatically, but 3 it's within 2 clicks.
- Right click on your project
- Choose
Export > Java > JAR file
- Choose included files and name output JAR, then click
Next
- Check "Save the description of this JAR in the workspace" and choose a name for the new
.jardesc
file
Now, all you have to 2 do is right click on your .jardesc
file and choose 1 Create JAR
and it will export it in the same spot.
Create an Ant file and tell Eclipse to build 17 it. There are only two steps and each is 16 easy with the step-by-step instructions 15 below.
Step 1 Create a build.xml file and add to 14 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 13 like the screenshot below. Note the Ant 12 icon on build.xml.
Step 2 Right-click on the root 11 node in the project. - Select Properties - Select 10 Builders - Select New - Select Ant Build - In 9 the Main tab, complete the path to the build.xml 8 file in the bin folder.
Check the Output
The Eclipse output 7 window (named Console) should show the following 6 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
EDIT: Some helpful comments by @yeoman and @betlista
@yeoman I think the correct 5 include would be /.class, not *.class, as 4 most people use packages and thus recursive 3 search for class files makes more sense 2 than flat inclusion
@betlista I would recomment 1 to not to have build.xml in src folder
Check out Apache Ant
It's possible to use Ant for automatic 1 builds with eclipse, here's how
This is possible by defining a custom Builder 8 in eclipse (see the link in Peter's answer). However, unless 7 your project is very small, it may slow 6 down your workspace unacceptably. Autobuild 5 for class files happens incrementally, i.e. only 4 those classes affected by a change are recompiled, but 3 the JAR file will have to be rebuilt and 2 copied completely, every time you save a 1 change.
Regarding to Peter's answer and Micheal's 5 addition to it you may find How Do I Automatically Generate A .jar File In An Eclipse Java Project useful. Because 4 even you have "*.jardesc" file 3 on your project you have to run it manually. It 2 may cools down your "eclipse click 1 hassle" a bit.
Using Thomas Bratt's answer above, just make sure your 3 build.xml is configured properly :
<?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="bin/" includes="**/*.class" />
</target>
</project>
(Notice 2 the double asterisk - it will tell build to look for .class 1 files in all sub-directories.)
Creating a builder launcher is an issue 7 since 2 projects cannot have the same external 6 tool build name. Each name has to be unique. I 5 am currently facing this issue to automate 4 my build and copy the JAR to an external 3 location.
I am using IBM's Zip Builder, but 2 that is just a help but not doing the real.
People 1 can try using IBM ZIP Creation plugin. http://www.ibm.com/developerworks/websphere/library/techarticles/0112_deboer/deboer2.html#download
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.