开发者

How do I add a folder full of Jar files to my classpath in Eclipse?

开发者 https://www.devze.com 2023-01-09 20:30 出处:网络
I would even want it to go recursively multiple folders down and grab a开发者_Go百科ll the jar files.You can\'t really do that through the IDE, but what you can do is do it outside the IDE and write a

I would even want it to go recursively multiple folders down and grab a开发者_Go百科ll the jar files.


You can't really do that through the IDE, but what you can do is do it outside the IDE and write a program to manually modify the .classpath file and add the jars.

For example, the .classpath file for your eclipse project is going to look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
 <classpathentry kind="src" path="src/java/main"/>
 <classpathentry kind="src" path="src/java/tests"/>
 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.5.0_17"/>
 <classpathentry kind="lib" path="test_reflib/commons-codec-1.3.jar"/>
 <classpathentry kind="lib" path="test_reflib/commons-collections-3.2.1.jar"/>
 <classpathentry kind="lib" path="test_reflib/commons-fileupload-1.1.1.jar"/>
</classpath>

So what you could do is write a program which scans the directories you pass into it, and manually modifies this .classpath file to contain the jars.

Personally, I never go to the trouble of doing this and just typically put all the jars I need in one folder and include them in the project. Or, if it's something like JBoss jars I need, I just include the ones I want.


Eclipse is really only putting a wrapper around standard Java capabilities, so you can add JARs or directories of classes easily because they correspond to standard Java classpath capabilities.

You could write your own classloader to follow any rules you like (and you will find that some app servers do actually do this.)

Otherwise you would need to follow @dcp's advice and script the edit of the classpath.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号