views:

1773

answers:

4

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.

A: 

Maybe this could help for generating the classes

When the plugin exist, you can open the plugin preferences and go to "java Compiler" - "Building" - "output Folder" - "Rebuild class files modified by others"

But creating a jar directly will not work i think. For this you should create an ANT file, you have to start manuall after a code change.

Markus Lausberg
Thanks for responding.
Dr. Faust
+2  A: 

A common pattern is to work against the class files in the project (projects can be added to other projects build paths and used at runtime while testing), so you don't actually need the jar files during development.

The geeneral approach for adding an automatic build step is to write an ant script, include that in your project and you can then have the execution of your ant script included in the project's build. So as ant has a pretty straighforward jar building task this isn't too much effort if you do need the jar file all the time. See for a starter.

djna
Thanks. This is very useful.
Dr. Faust
+3  A: 
VonC
Thanks. Very helpful.
Dr. Faust
+1 you never learn to much. Nice
Markus Lausberg
A: 

Create a J2EE Utility project (Util). It lets you create an association with a J2EE project (ProjectX). When you edit the properties of ProjectX to depend upon the Util project, it shows Util as Util.jar. With the dependency declared, Eclipse will build the Util.jar when it has to build the Util project. If you have auto-build active for the Util project, the .jar file will be kept in sync each time the project is built. If your target project isn't a J2EE one, you can still use this solution but use a dummy J2EE parent project.

Here is the link to the help page for using the ANT task for building a .zip file from within Eclipse: http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.pde.doc.user/tasks/pde_feature_generating_ant.htm

An alternate solution is to use the Zip plugin. We used this over 5 years ago but stopped when WSAD included support for dependent projects as .jar files.

Kelly French
Thanks for the response.
Dr. Faust