Friday, April 8, 2011

Using Eclipse "User Libraries" with Ant

An Eclipse User Library is simply a set of JAR files defined within the IDE.  It provides a convenient way to organize and include jars in your project's build path without having to actually import the jars into your project and having them get deployed with your project.  User Libraries can be reused across multiple projects.  I haven't tried it myself, but it appears the User Libraries can be shared across machines with minimal hoop jumping.

So far so good.  But how will Ant access these User Libraries?  As far as I can determine, there's no out-of-the-box way for Ant to reference an Eclipse's User Library in it's classpath.  Here's a couple of relevant forum posts on the topic:
So what's the solution? Here's the options I've seen so far:
  1. Use the Eclipse User Library as-is then configure the Ant build file separately for the jars you need in your classpath.  I consider this option the "hard way" and of course it's what I'm doing for now.
  2. Use Apache Maven instead of Ant for build and project dependencies.  I'd like to give this a try when I have time. 
  3. I've seen a few people suggest using Ant4Eclipse.  I haven't had time to try it myself yet but it sounds like a potential solution.
  4. Don't utilize Eclipse User Libraries and copy your required jars to a /lib folder in your project.  Of course, this is just ignoring the issue isn't it. :)
I'm interested in other approaches and options for this problem.  Please feel free to comment.  Thanks.

5 comments:

  1. Trying to solve this same issue, would love to see an elegant solution myself.

    ReplyDelete
  2. I used to have multiple copies of the same jars in each project and have finally moved them all to user libraries. Of course I then ran into the same headache as you.

    I'm not sure the method I've gone for is any better, but here it is.

    1. I have a common.properties file that defines a variable the base folder (common.lib.folder) for all the user libraries and then further variables for each user library (e.g. common.log4j). I place this file in the root folder of all the library folders.

    2. For a project, in the build.properies I define a variable named common.properties which points to the file in step 1 (in case other developers have the libraries in a different folder).

    3. The variables from the common file are now available to use in the command.

    Hope that makes sense.

    ReplyDelete
  3. Ah the joys of filtering out anything that looks like cross-site scripting.

    What I was trying to write was I reference a fileset with dir="${common.lib.folder}/${common.log4}"

    ReplyDelete