0

Scenario

Let's say I have an Eclipse workspace with Project A, Project B, and Project C in it. Is there any way that I can configure eclipse to create a folder (anywhere) under my workspace called build that gets Project A.jar, Project B.jar, and Project C.jar when a build is executed? (Note that it doesn't have to automatically build, this can be something I click on to launch.)

I'm open to a number of solutions, including Ant, as long as it meets the requirements below.

Requirements

  1. Project A.jar must contain all of the classes and resource files that would typically appear in /Project A/bin/ when Eclipse does a build.

  2. When I add Project D to my workspace, I don't want to have to do anything special to Project D to make it play nicely with the build setup. That is, simply adding Project D to the workspace in eclipse will cause Project D.jar to appear in the build folder the next time a build is run. All of these requirements should also be satisfied for Project D with only standard Eclipse configuration for dependencies, etc.

  3. The classpath and other required build settings that are set in the eclipse project should carry through to the JAR files. That is, if Project A.jar requires Project B.jar to be able to run, then Project B.jar should be included in the classpath of Project A.jar.

  4. As a further extension of 3, 3rd party libraries that are not projects in the eclipse workspace must also be copied and referenced. That is, if Project A.jar requires spring.jar, spring.jar must also be copied to build and a reference must be added to the Project A.jar classpath. It would be really nice if these 3rd party libraries could go in a /build/lib folder.

  5. It cannot rely on any 3rd party tools or plugins that do not come with Eclipse Helios.

Related

Build project into a JAR automatically in Eclipse seems to be related and it may fit requirement 1 and 5, but I do not believe it fits any of the other 3.

Community
  • 1
  • 1
Luke
  • 3,742
  • 4
  • 31
  • 50
  • And what have you tried? Apologies for sounding nasty, but it's time to learn ANT. – Mark O'Connor Jul 02 '12 at 19:40
  • @MarkO'Connor Ant is fine, and that's what I'm using now, but my current solution isn't flexible enough. As long as I can create an Ant script that is generic enough to meet the 5 requirements above and it pulls it's configuration information from eclipse (somehow) then I'm fine with it. I just want to avoid maintaining project settings in both Eclipse and Ant build files. In practice they'll get out of sync and it'll be a nightmare. – Luke Jul 02 '12 at 19:46

2 Answers2

1

I ended up writing a Java program that made use of org.apache.tools.ant.Project to run a simple Ant script. The Java program parses the .classpath files and sets the appropriate user properties for the Ant script to use (jar output path, classpath, etc).

It might not be the perfect solution, but it was the easiest for me to implement and it meets my requirements.

If you're willing to use a 3rd party plugin for eclipse, it looks like Ant4Eclipse might be a good solution. That's not an option for me, so I didn't test it.

Luke
  • 3,742
  • 4
  • 31
  • 50
0

There is no easy solution for what you are after. If you remove requirement #5, others may help you find a third-party solution.

If you just have base Eclipse and Ant at your disposal, you can certainly write an Ant script that is completely generic, iterates over projects, parses .classpath files, compiles, builds JARs, etc. Not easy, but certainly possible.

Konstantin Komissarchik
  • 28,879
  • 6
  • 61
  • 61