当从Maven的蚂蚁运行插件运行Ant任务我可以设置Maven的类路径蚂蚁财产。 然而,当我尝试运行<ant:java
任务设置这个确切的classpath中我得到了错误的引用不能找到。 仿佛整个classpath中被解释为一个罐子。 有没有办法以某种方式设置此类路径蚂蚁java的任务是什么?
(从行家)
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
....
<property name="compile_classpath" refid="maven.compile.classpath"/>
....
(从蚂蚁)...
<path id="classpath">
<path refid="${compile_classpath}"/>
</path>
...
<java classname="..." classpathref="classpath">
...
</java>
Maven的蚂蚁运行插件的版本是1.7
如果不能这样做是有蚂蚁某种方式来遍历这个类路径字符串(用jar文件的位置“;”分隔符),并设置罐子位置的值作为“
我想我已经打在解决这一感到沮丧了一段时间后:灵感来自这个线程
该antrun插件正确构建类路径的引用,而不是将它们通过向外部构建文件,当你调用ant
任务。
所以,解决的办法是在要使用访问任何classpath中引用明确地传递<reference>
元素。
<!-- 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>
和使用他们作为正常Ant构建任务
<!-- 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>
在行家:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
....
<property name="compile_classpath" refid="maven.compile.classpath"/>
....
在蚂蚁使用pathelement替代路径REFID
<path id="classpath">
<pathelement path="${compile_classpath}"/>
</path>
那么它的工作
您在这里的问题是,compile_classpath是一个Ant属性。 表达式$ {} compile_classpath解析为属性的值。
而路径元素上的REFID属性要求引用的路径。 基本上,你得到一个运行时类型错误的路径裁判预期,但您所提供的字符串。
你真正想要做的是直接通过maven.compile.classpath到你的Ant路径元素。 由于两个正在处理路径对象。 但是,这是行不通的。
所以,我想出了一个解决方法是将路径传递到各个罐子从Maven来Ant构建文件属性。
在Maven的:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
...
<property name="example.jar"
value="${org.example.example:example-artifact:jar}"/>
...
在蚂蚁:
<path id="classpath">
<path location="${example.jar}"/>
</path>
这工作,但显然是可怕的,如果你有在Maven类路径不止一个依赖或要传递的传递依赖。 我认为蚂蚁常春藤可能是我要带我的生成文件的方式。
对不起,rebump一个古老的线程,但今天运行到这个自己后,我注意到Maven的文档中有一个错误。 正如你所发现的
<property name="compile_classpath" refid="maven.compile.classpath"/>
不工作。 然而,
<property name="compile_classpath" value="${maven.compile.classpath}"/>
应该管用。 当然,你也可以使用${maven.compile.classpath}
直接。
错误追踪声称,该文档错误是Maven的4年以前固定的 ,但今天的日期,它仍然存在的最后一个文档中推(在2011年年底)。