如何覆盖存储在 ant lib 目录中的 ant 任务
在我的工作中,我们在一些 Java 项目中使用 AspectJ。为了使其能够与 ant 构建一起使用,我们将aspectjtools.jar 放置在ant/lib/ 中。
我现在正在开发一个特定的 Java 项目,需要使用更新版本的aspectJ。我不想让每个使用该项目的人都更新他们的本地副本aspectjtools.jar。相反,我尝试将较新的aspectjtools.jar 添加到项目的lib 目录中,并将以下行添加到build.xml 中。
<taskdef
resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"
classpath="./lib/aspectjtools.jar" />
然而,这并没有像我希望的那样工作,因为 ANT 类加载器从 ant/lib/ 加载 jar,而不是我在 taskdef 类路径中指定的 jar。
有没有什么办法可以强制蚂蚁选择签入我的项目的罐子?
At my work we use AspectJ in some of our Java projects. To get this to work with ant builds we have been placing aspectjtools.jar within ant/lib/.
I am now working on a particular Java project and need to use a newer version of aspectJ. I don't want to have to get everyone who uses the project to update their local copy of aspectjtools.jar. Instead, I tried adding the newer aspectjtools.jar to the lib directory of the project and adding the following line to build.xml.
<taskdef
resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"
classpath="./lib/aspectjtools.jar" />
However, this doesn't work as I hoped as the ANT classloader loads jars from ant/lib/ in preference to the jar I specify in the taskdef classpath.
Is there any way to force ant to pick the jar checked into my project instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
难道你不能更新 iajc 编译目标以在类路径上使用新的 jar 吗?
不可能强制类加载器优先选择给定的 jar 文件而不是另一个文件。如果您必须涉及同一类的多个版本,那么您应该考虑 OSGI。
最简单的解决方案是仅使用项目或 Maven/Ivy 存储库中的库,并忽略全局 ant 文件夹中的库。
示例:
更新:
您还必须使用另一个 Ant。如果您使用的是 Eclipse,请直接从 Ant 视图尝试捆绑的版本。
您还有另一种选择,但它有点困难。即使用 AspectJ 加载时编织来代替。如果您选择该选项,则可以使用普通编译任务进行编译,但必须在启动时使用 JVM 代理进行编织。您可以阅读有关它的更多信息 此处。
我希望这有帮助!
can't you just update the iajc compile target to use the new jar on the classpath?
It's not possible to force the classloader to prefer a given jar file over another one. If you must relate to several version of the same class, then you should consider OSGI.
The simplest solution will be to just use libraries from the project or a Maven/Ivy repository and ignore the libraries in your global ant folder.
An example:
Updated:
You also have to use another Ant. If you're using Eclipse, try the bundled one directly from the Ant view.
You also have another option, but it's a little bit more difficult. That is to use AspectJ load-time weaving instead. If you go for that option, you can compile with an ordinary compile task, but you have to do the weaving with an JVM agent at startup. You can read more about it here.
I hope this helps!
我的问题的最终答案是否定的。目前,ANT 无法优先使用项目中的任务 jar 而不是 ANT lib 目录中的任务 jar。
The ultimate answer to my question is no. The is currently no way for ANT to use a task jar from a project in preference to a task jar in the ANT lib directory.
这是可能的。
您需要利用这个额外的任务来创建一个新的类加载器
http://enitsys.sourceforge.net /ant-classloadertask/
This is possible.
You need to make use of this extra task to create a new class loader
http://enitsys.sourceforge.net/ant-classloadertask/
我在项目中使用 Spotbugs 时遇到了类似的问题,同时仍然在
ant/lib
中全局安装了findbugs-ant.jar
。我想找到一种方法来完成这项工作,而不必从 ant 安装中删除 findbugs jar(其他项目分支仍在使用)。虽然我没有发现任何可能在内部
build.xml
声明此内容,但 ant 的-lib
命令行参数却成功了:来自 ant 文档:
因此,通过在 -lib 参数中指定我的本地 Spotbugs 安装,我能够运行 ant 构建并使 ant 的类加载器更喜欢这些 Spotbugs jar 文件,而不是 ANT_HOME/lib 中的旧 findbugs jar 文件。
蚂蚁呼叫示例:
ant -lib my/local/path/to/spotbugs/lib Spotbugs
I just had a similar problem when using Spotbugs in a project while still having
findbugs-ant.jar
installed globally inant/lib
. I wanted to find a way to get this working without having to delete the findbugs jar from the ant installation (that's still used by other project branches).While I did not find any possibility to declare this inside
build.xml
, ant's-lib
command line argument did the trick:From ant documentation:
So by specifying my local spotbugs installation in the -lib argument, I was able to run the ant build and make ant's class loader prefer these spotbugs jar files to the older findbugs jar in ANT_HOME/lib.
example ant call:
ant -lib my/local/path/to/spotbugs/lib spotbugs