eclipse 将用户库添加到 Ant Builder 类路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3651423/
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
Add user libraries to Ant Builder classpath
提问by Nuker
I am having a problem with setting up an Ant Builder for my Eclipse projects.
我在为 Eclipse 项目设置 Ant Builder 时遇到问题。
I do have several 3rd party libs configured as user libraries within Eclipse. Those libraries are added to the build path of my projects and everything is working fine.
我确实有几个 3rd 方库配置为 Eclipse 中的用户库。这些库被添加到我的项目的构建路径中,并且一切正常。
My problem is, that if I want to use the Ant Builder from Eclipse, I will have to add some of the user libraries to the classpath of the Ant Builder to get it working. I need those Libs because they include several task defs and type defs for Ant, NOT TO COMPILE MY PROJECTS. But how can I add those user libraries to the Ant Builder classpath? I don't want to "hard-code" them by adding them manually, because if I must change one those libs in the future, I will also have to maintain all Ant Builders. And I dont't know how load determine the path to the user libraries at runtime within Ant to load them dynamically, because I need those libs at the bootstrap of Ant to be able to define my needed Ant Tasks successfully.
我的问题是,如果我想从 Eclipse 使用 Ant Builder,我必须将一些用户库添加到 Ant Builder 的类路径中才能使其工作。我需要那些 Libs,因为它们包括几个任务定义和 Ant 的类型定义,而不是编译我的项目。但是如何将这些用户库添加到 Ant Builder 类路径中?我不想通过手动添加来“硬编码”它们,因为如果我将来必须更改这些库中的一个,我还必须维护所有 Ant Builder。而且我不知道负载如何在 Ant 中确定运行时用户库的路径以动态加载它们,因为我需要 Ant 引导程序中的那些库才能成功定义我需要的 Ant 任务。
回答by Isaac
In that case, you may wish to add your JAR files (containing the taskdefs) to the Ant runtime.
在这种情况下,您可能希望将 JAR 文件(包含 taskdef)添加到 Ant 运行时。
Window -> Preferences, select "Ant -> Runtime" from the left. Focus on "Global Entries", then use the "Add JAR" button on the right to add JAR files.
Window -> Preferences,从左边选择“Ant -> Runtime”。关注“全局条目”,然后使用右侧的“添加 JAR”按钮添加 JAR 文件。
The JAR files you add will be contributed to any Ant process running under Eclipse.
您添加的 JAR 文件将提供给在 Eclipse 下运行的任何 Ant 进程。
Your next question might be - "why do I have to add JARs? Can't I add my user library?". Good question, glad you (were almost about to) asked. Drives me bonkers too and I have no idea why Eclipse doesn't provide this functionality. Maybe it's time to open a feature request...
您的下一个问题可能是 - “为什么我必须添加 JAR?我不能添加我的用户库吗?”。好问题,很高兴你(几乎要)问。也让我发疯,我不知道为什么 Eclipse 不提供此功能。也许是时候打开功能请求了...
EditFebruary 2014: turns out that adding user libraries to Ant's classpath has already been requested (https://bugs.eclipse.org/bugs/show_bug.cgi?id=211669). By the looks of it, I was the one who reopened it...
2014 年 2 月编辑:原来已经请求将用户库添加到 Ant 的类路径(https://bugs.eclipse.org/bugs/show_bug.cgi?id=211669)。看样子,我是重新打开它的人......
回答by Lucas
Im not sure if this will help you, but I like to use Ivy in this situation. I have a custom ant extension which I include that way:
我不确定这是否会帮助你,但我喜欢在这种情况下使用 Ivy。我有一个自定义的 ant 扩展,我以这种方式包括在内:
build.xml:
构建.xml:
<project name="project" basedir="." default="deploy" xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:myNamespace="antlib:org.company.module">
<property file="build.${user.name}.properties" />
<property file="build.${env.COMPUTERNAME}.properties" />
<property file="build.properties" />
<property file="build-base.properties" />
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" />
<!-- Configuration for external ant libs -->
<property name="apache.ant.ext.lib" value="${target.root}/antlib" />
<mkdir dir="${apache.ant.ext.lib}" />
<ivy:retrieve inline="true" pattern="${apache.ant.ext.lib}/[artifact]-[revision]-[type].[ext]"
conf="master" organisation="org.company" module="module" revision="1.0" />
<path id="apache.ant.ext.lib.classpath">
<fileset dir="${apache.ant.ext.lib}" includes="*.jar" />
</path>
<taskdef classpathref="apache.ant.ext.lib.classpath" resource="path/to/antlib.xml" />
...
then your libs will be retrieved into your temporary ant ext lib folder for ant to use during its runtime, but will be excluded from your project. Eclipse has a plugin for Ivy (IvyDE) and this technique has made my life much simpler.
那么您的库将被检索到您的临时 ant ext lib 文件夹中,以便 ant 在其运行时使用,但将从您的项目中排除。Eclipse 有一个 Ivy 插件(IvyDE),这种技术让我的生活变得更简单。
回答by Reinstate Monica 2331977
Adding new user/external jars manually is cumbersome - you're right.
手动添加新的用户/外部 jar 很麻烦 - 你是对的。
I've found that the best way to avoid having to do this is to change your ANT_HOME from the Ant bundled with Eclipse to a standalone Ant installation that can be used from any IDE, command line, etc.
我发现避免这样做的最佳方法是将 ANT_HOME 从与 Eclipse 捆绑的 Ant 更改为可从任何 IDE、命令行等使用的独立 Ant 安装。
Go to Window > Preferences
, and in the left pane, select Ant > Runtime
. Select the Ant Home
button on the right of the window and select the root directory of your standalone Ant installation. Eclipse will be kind enough to update the Ant Home Entries in the main pane to use this installation instead. I'm using Eclipse Juno here - instructions may be slightly different for other versions.
转到Window > Preferences
,然后在左窗格中选择Ant > Runtime
。选择Ant Home
窗口右侧的按钮,然后选择独立 Ant 安装的根目录。Eclipse 会更新主窗格中的 Ant Home Entries 以使用此安装。我在这里使用 Eclipse Juno - 其他版本的说明可能略有不同。
Now any jars dropped into ANT_HOME/lib will be accessible from your build.xml files without having to manually add them to the classpath.
现在,任何放入 ANT_HOME/lib 的 jar 都可以从 build.xml 文件访问,而无需手动将它们添加到类路径中。
I'd like to give credit to Qasim Rasheed for showing me this method in his blog at http://www.qasimrasheed.com/post.cfm/eclipse-configure-ant-home. It's much better than manually replacing the Ant Home Entries (which results in your problem of having to update at this screen every time a new jar is added).
我想感谢 Qasim Rasheed 在他的博客http://www.qasimrasheed.com/post.cfm/eclipse-configure-ant-home 中向我展示了这种方法。这比手动替换 Ant Home 条目要好得多(这会导致每次添加新 jar 时都必须在此屏幕上更新的问题)。