score:27

Accepted answer

check out apache ant

it's possible to use ant for automatic builds with eclipse, here's how

score:0

creating a builder launcher is an issue since 2 projects cannot have the same external tool build name. each name has to be unique. i am currently facing this issue to automate my build and copy the jar to an external location.

i am using ibm's zip builder, but that is just a help but not doing the real.

people can try using ibm zip creation plugin. http://www.ibm.com/developerworks/websphere/library/techarticles/0112_deboer/deboer2.html#download

score:1

using thomas bratt's answer above, just make sure your 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 the double asterisk - it will tell build to look for .class files in all sub-directories.)

score:5

regarding to peter's answer and micheal's addition to it you may find how do i automatically generate a .jar file in an eclipse java project useful. because even you have "*.jardesc" file on your project you have to run it manually. it may cools down your "eclipse click hassle" a bit.

score:13

this is possible by defining a custom builder in eclipse (see the link in peter's answer). however, unless your project is very small, it may slow down your workspace unacceptably. autobuild for class files happens incrementally, i.e. only those classes affected by a change are recompiled, but the jar file will have to be rebuilt and copied completely, every time you save a change.

score:72

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 configuration build 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

edit: some helpful comments by @yeoman and @betlista

@yeoman i think the correct include would be /.class, not *.class, as most people use packages and thus recursive search for class files makes more sense than flat inclusion

@betlista i would recomment to not to have build.xml in src folder

score:292

you want a .jardesc file. they do not kick off automatically, but it's within 2 clicks.

  1. right click on your project
  2. choose export > java > jar file
  3. choose included files and name output jar, then click next
  4. check "save the description of this jar in the workspace" and choose a name for the new .jardesc file

now, all you have to do is right click on your .jardesc file and choose create jar and it will export it in the same spot.


Related Query

More Query from same tag