views:

1246

answers:

6

I have an eclipse's .classpath file that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="test"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="output" path="bin"/>
    <classpathentry kind="lib" path="/libraries/jee/servlet-api.jar"/>
    <classpathentry kind="lib" path="/libraries/junit/junit-4.6.jar"/>
    <classpathentry kind="lib" path="/libraries/log4j/log4j-1.2.15.jar"/>
</classpath>

I'd like to add a whole directory of jars to the classpath - I like eclipse (or more precisely, our ant-based build process that uses .classpath format) to know several jars that reside in a single directory, without specifying them directly. How can I do that?

+2  A: 

I'm not sure eclipse can do that itself.

You could try

  1. Move to Maven for you build system and then it's eclipse:eclipse command will generate the .classpath file for you
  2. Get ant to modify the .classpath after a build. After all, it's just xml
gommo
It's a tactical problem - if there existed a built-in option, I'd have used it.For now, I'll just list all the jars manually.Thanks
ripper234
A: 

Place all the jars under one libraries folder

use javac -classpath c:\com\whichever\libraries* program1.java

A: 

Eclipse does not work that way I'm afraid. The best solution I can think of is to generate the .classpath file from script which scans the directory for jars.

Robert Munteanu
+1  A: 

There's a developerworks article that show how to implement a custom classpath container that exposes the contents of a directory. You'll need to register to view the article and download the sources.

Rich Seller
A: 

IVY contains an ANT task that will create an XML file listing the location of the jar dependencies that it manages.

http://ant.apache.org/ivy/history/latest-milestone/use/artifactreport.html

It would be very straight forward to combine this with an XSLT stylesheet to afterwards generate the Eclipse .classpath file.

Mark O'Connor
+1  A: 

My colleague implemented a classpath container which recursivly looks for jars in a given directory within the workspace, have a look at http://openscada.org/news/dx/31.05.2010154336JREJ4U.htm

The update site can be found at http://repo.openscada.org/p2/bob/R

The plugin is licensed unter LGPL V3 and you can find the source code under http://pubsvn.inavare.net/openscada/modules/bob/trunk/

Mauli