Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include multiple jars with classpathentry

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?

like image 632
ripper234 Avatar asked Jul 02 '09 10:07

ripper234


People also ask

How do I include all JARs in a folder classpath?

In general, to include all of the JARs in a given directory, you can use the wildcard * (not *. jar ). The wildcard only matches JARs, not class files; to get all classes in a directory, just end the classpath entry at the directory name.

How do I select multiple JARs in eclipse?

Hold the shift key down while clicking on additional jars to add within the folder. This will allow you to select and add more than one at a time.

What should classpath be set to?

The default value of CLASSPATH is a dot (.). It means the only current directory searched. The default value of CLASSPATH overrides when you set the CLASSPATH variable or using the -classpath command (for short -cp). Put a dot (.)


2 Answers

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
like image 170
Colin Goudie Avatar answered Oct 07 '22 22:10

Colin Goudie


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/2010/05/31/adding-a-directory-as-class-path-to-eclipse/

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 git://git.openscada.org/ (http://git.openscada.org/?p=org.openscada.bob.git;a=tree)

like image 25
Mauli Avatar answered Oct 07 '22 20:10

Mauli