Include multiple jars with classpathentry

…衆ロ難τιáo~ 提交于 2019-12-08 17:36:16

问题


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?


回答1:


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



回答2:


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)




回答3:


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.




回答4:


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.




回答5:


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.




回答6:


Try http://ant-eclipse.sourceforge.net this works quite well, An active fork is at https://github.com/javajoesb/ant-eclipse




回答7:


Place all the jars under one libraries folder

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



来源:https://stackoverflow.com/questions/1073693/include-multiple-jars-with-classpathentry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!