类路径问题:使用 Maven Antrun 插件运行 ant java 任务 [英] Classpath problems:running ant java task with Maven Antrun plugin

查看:28
本文介绍了类路径问题:使用 Maven Antrun 插件运行 ant java 任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当从 maven ant run 插件运行 ant 任务时,我可以将 maven 类路径设置为 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"/>
   ....

(来自蚂蚁)...

<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

如果这不能完成,ant 中是否有某种方法来迭代这个类路径字符串(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.

因此,解决方案是使用 元素显式传入您要访问的任何类路径引用.

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>

并在您的 ant 构建任务中正常使用它们

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆