tags:

views:

2092

answers:

3

I have an eclipse project where I want to keep my java project built into a Jar automatically. I know I have an option to export the project into a jar; if I do a right click; but what I am really looking for is, that like eclipse automatically builds a project's class files and put them in target folder; it should also build a jar automatically and copy the latest jar at some or a specific location.

Is there a option to configure eclipse in such a way, to build jars automatically?

-edit Just to make it clear for guys, paitent enough to answer my question; I am not looking at ant as solution; as I already use it, but what I would like it something that gets initiated automatically either with a time based trigger or immediate build with change.

+4  A: 

Check out Apache Ant

It's possible to use Ant for automatic builds with eclipse, here's how

Peter
I am already using Apache ant to do the builds and make Jar. But what I was really looking for was a way around apache ant, and directly using eclipse.
Priyank
Apologies, I didn't go through the article in link earlier. It indeed talks about what I need. Thanks.
Priyank
+1  A: 

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.

Michael Borgwardt
+6  A: 

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

  1. Right click on your project.
  2. Chose Java --> JAR file
  3. Choose included files and name output jar, click "Next"
  4. Check "Save the description of this JAR in the workspace" and chose a name for the new jardesc file.

Now, all you have to do is right click on your jardesc file and chose "Create JAR" and it will export it in the same spot.

Konrad
Sad that this answer didn't get more upvotes (or best answer) months ago. Oh well, by now Konrad is gone.
Yar
In Eclipse Galileo, I had to replace your step 1 with File -> Export -> Java -> JAR file.
Matt Huggins