【问题标题】:Ant-Junit classpath from property来自属性的 Ant-Junit 类路径
【发布时间】:2014-07-22 01:30:06
【问题描述】:

我在项目中有以下 Ant 目标和路径元素。

<project>
.....
<path id="MyProject.classpath" location="${class.path}">
    <pathelement location="${output.directory}/ant-junit.jar" />
    <pathelement location="${output.directory}/junit.jar" />
    <fileset dir="${output.directory}">
        <include name="**/*.jar" />
    </fileset>
    <pathelement location="${class.path}"/> <!-- This did not work -->
    <dirset dir="${dest.path}">         
    </dirset>
</path>

<path id="classpath.test">
    <fileset dir="${output.directory}">
        <include name="**/*.jar" />
    </fileset>
</path>

<target name="test">      
    <echo>In Test</echo>  
    <mkdir dir="${junit.output.dir}" />
    <junit>
        <classpath refid="MyProject.classpath">
        </classpath>           
        <batchtest todir="${junit.output.dir}">
            <formatter type="plain" usefile="false"/>
            <formatter type="plain" />
            <fileset dir="${src.path}">
                <include name="**/*Test*.java" />
            </fileset>
        </batchtest>    
    </junit>
</target>
....
</project>

我有一个属性class.path 指向一堆像下面这样的罐子。我想使用这个class.path(由IDE创建)属性作为上述junit测试类路径的类路径,我尝试了一些东西,它没有工作。有人能指出我正确的方向吗?

<condition property="class.path" value="C:/tools/bea/jdk142_19/jre/lib/rt.jar;C:/tools/bea/jdk142_19/jre/lib/jsse.jar;C:/tools/bea/jdk142_19/jre/lib/jce.jar;C:/tools/bea/jdk142_19/lib/tools.jar;${platformhome.local.directory}/server/lib/knex.jar;${platformhome.local.directory}/common/lib/log4j.jar;${platformhome.local.directory}/server/lib/debugging.jar;${platformhome.local.directory}/javelin/lib/javelin.jar;${platformhome.local.directory}/server/lib/wlw-lang.jar;${platformhome.local.directory}/server/lib/weblogic.jar;${platformhome.local.directory}/common/eval/pointbase/lib/pbserver44.jar;${platformhome.local.directory}/common/eval/pointbase/lib/pbclient44.jar;${platformhome.local.directory}/server/lib/webservices.jar;${platformhome.local.directory}/server/lib/webserviceclient.jar;${platformhome.local.directory}/server/lib/webserviceclient+ssl.jar;${platformhome.local.directory}/server/lib/wli.jar;${platformhome.local.directory}/server/lib/xbean.jar;${platformhome.local.directory}/server/lib/wlxbean.jar;${platformhome.local.directory}/server/lib/xqrl.jar;${platformhome.local.directory}/server/lib/netui/netui-compiler.jar;${app.local.directory}/APP-INF/lib/CommonUtilities.jar;${app.local.directory}/APP-INF/lib/junit.jar;${app.local.directory}/APP-INF/lib/log4j.jar">
       <or>
         <os family="windows"/>
         <os name="SunOS"/>
       </or>
     </condition>     

【问题讨论】:

    标签: java ant junit


    【解决方案1】:

    &lt;pathelement location= ...&gt;:location 属性指定 单个文件 或相对于项目的基本目录(或绝对文件名)的目录,而 path 属性接受 冒号-或以分号分隔的位置列表。
    path 属性旨在与预定义的路径一起使用 - 在任何其他情况下,应该首选具有位置属性的多个元素。

    ..来自HERE

    使用&lt;pathelement path="${class.path}" /&gt; 应该可以工作,除非还有更多错误。

    【讨论】:

      【解决方案2】:

      我不明白您是如何实现 Ant 类路径的。这是我的,希望对您有所帮助:

      <path id="project_classpath">
         <fileset dir="${dir_sandbox_jar_dependencies}" includes="*.jar"/>
         <pathelement location="${build.class.dir}"/>
      </path>
      

      然后我用它

      <java classname="some.java.class" failonerror="true" classpathref="project_classpath">
         <arg value="hello"/>
      </java>
      

      classpathref 是许多任务的参数,例如javac、java 和javadoc

      它也被接受——我认为——作为 JUnit 任务中的 nested element。

      【讨论】:

      • 你好 aliteralmind,ant 类路径在 build.xml 文件中。我需要将类路径设置为 junit 任务。但路径位于属性 class.path 之一中。
      • 是的。我不积极。我希望分享我使用的东西可能会有所帮助。
      猜你喜欢
      • 1970-01-01
      • 2011-02-17
      • 2015-08-20
      • 2017-06-20
      • 1970-01-01
      • 1970-01-01
      • 2011-11-01
      • 2011-11-22
      • 1970-01-01
      相关资源
      最近更新 更多