类路径问题:使用Maven Antrun插件运行ant java任务 [英] Classpath problems:running ant java task with Maven Antrun plugin
问题描述
从maven ant run插件运行ant任务时,我可以将maven classpath设置为ant属性.但是,当我尝试运行<ant:java
任务设置此确切的类路径时,出现了找不到该引用的错误.好像整个类路径被解释为一个jar.有什么办法可以将此类路径设置为ant java任务吗?
When running ant task from maven ant run plugin I can set maven classpath as an ant property. However when I try to run <ant:java
task setting this exact classpath I get the error that the reference can not be find. As if the whole classpath is interpreted as one jar. Is there a way to somehow set this classpath to ant java task?
(来自Maven)
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
....
<property name="compile_classpath" refid="maven.compile.classpath"/>
....
(来自ant) ...
(from ant) ...
<path id="classpath">
<path refid="${compile_classpath}"/>
</path>
...
<java classname="..." classpathref="classpath">
...
</java>
maven ant run插件的版本为1.7
The version of maven ant run plugin is 1.7
如果无法做到这一点,那么蚂蚁可以通过某种方法来迭代该类路径字符串(使用';'分隔符的jar文件的位置)并将jar位置的值设置为'
If this can not be done is there some way in ant to iterate this classpath string (location of jar files with ';' separator) and set the values of jar location as '
推荐答案
I think I've hit on the solution to this one after being frustrated for some time : inspired by this thread
antrun插件可以正确地构造类路径引用,但是在调用ant
任务时不会将它们传递给外部构建文件.
The antrun plugin is correctly constructing classpath references, but not passing them through to the external build file when you invoke the ant
task.
因此解决方案是使用<reference>
元素显式传递要访问的任何类路径引用.
So the solution is to explicitly pass in any classpath references you want to access using the <reference>
element.
<!-- antrun plugin execution -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>build</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<ant antfile="${basedir}/build.xml">
<!-- This is the important bit -->
<reference torefid="maven.compile.classpath" refid="maven.compile.classpath"/>
</ant>
</target>
</configuration>
</execution>
</executions>
</plugin>
并在您的蚂蚁构建任务中像往常一样食用它们
And consume them as normal in your ant build task
<!-- External ant build referencing classpath -->
<java classname="net.nhs.cfh.ebook.Main" fork="true" failonerror="true">
<arg value="-b"/>
<arg value="${dist.dir}"/>
<arg value="-o"/>
<arg value="${xml.dir}/treeindex"/>
<arg value="tree.xml"/>
<jvmarg value="-Dstrategy=treeParser"/>
<!-- reference to the passed-in classpath reference -->
<classpath refid="maven.compile.classpath"/>
</java>
这篇关于类路径问题:使用Maven Antrun插件运行ant java任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!