eclipse 包含多个带有 classpathentry 的 jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1073693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Include multiple jars with classpathentry
提问by ripper234
I have an eclipse's .classpath file that looks like this:
我有一个 eclipse 的 .classpath 文件,看起来像这样:
<?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?
我想将整个 jar 目录添加到类路径 - 我喜欢 eclipse(或者更准确地说,我们使用 .classpath 格式的基于 ant 的构建过程)来了解驻留在单个目录中的几个 jar,而无需直接指定它们. 我怎样才能做到这一点?
采纳答案by Colin Goudie
I'm not sure eclipse can do that itself.
我不确定 eclipse 本身可以做到这一点。
You could try
你可以试试
- Move to Maven for you build system and then it's eclipse:eclipse command will generate the .classpath file for you
- Get ant to modify the .classpath after a build. After all, it's just xml
- 移动到 Maven 为您构建系统,然后它的 eclipse:eclipse 命令将为您生成 .classpath 文件
- 在构建后获取 ant 来修改 .classpath。毕竟只是xml
回答by Mauli
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/
我的同事实现了一个类路径容器,它递归地在工作区中的给定目录中查找 jar,请查看http://openscada.org/2010/05/31/adding-a-directory-as-class-path-to -蚀/
The update site can be found at http://repo.openscada.org/p2/bob/R
更新站点可以在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)
该插件在 LGPL V3 下获得许可,您可以在 git://git.openscada.org/ ( http://git.openscada.org/?p=org.openscada.bob.git;a=tree)
回答by Java Joe
Try http://ant-eclipse.sourceforge.netthis works quite well, An active fork is at https://github.com/javajoesb/ant-eclipse
试试http://ant-eclipse.sourceforge.net这很好用,一个活跃的叉子是在https://github.com/javajoesb/ant-eclipse
回答by Robert Munteanu
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.
Eclipse 恐怕不能那样工作。我能想到的最佳解决方案是.classpath
从扫描 jar 目录的脚本生成文件。
回答by Rich Seller
There's a developerworks articlethat 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.
有一篇developerworks 文章展示了如何实现一个公开目录内容的自定义类路径容器。您需要注册才能查看文章并下载源代码。
回答by Mark O'Connor
IVY contains an ANT task that will create an XML file listing the location of the jar dependencies that it manages.
IVY 包含一个 ANT 任务,该任务将创建一个 XML 文件,列出它管理的 jar 依赖项的位置。
http://ant.apache.org/ivy/history/latest-milestone/use/artifactreport.html
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.
将它与 XSLT 样式表结合起来以生成 Eclipse .classpath 文件将是非常直接的。
回答by Mark O'Connor
Place all the jars under one libraries folder
将所有罐子放在一个库文件夹下
use javac -classpath c:\com\whichever\libraries* program1.java
使用 javac -classpath c:\com\whichever\libraries* program1.java