簡體   English   中英

Ant任務參數的順序

[英]Order of Ant Task Arguments

我是Ant的新手,昨天在一些幫助下編寫了一個簡單的build.xml。 但是,在查看了運行ant -verbose的輸出后,似乎沒有正確調用我必須處理許多JUnit測試的類。

<project name="JUnit_tests" default="run" basedir=".">

<!-- Define variable properties -->
<property name="src" value="${basedir}"/>
<property name="junit" value="org.junit.runner.JUnitCore"/>

<!--<property name="junit" value="org.junit.runner.JUnitCore"/>-->

<!-- Appends all jars in the current directory to the classpath -->
<path id="compile.classpath">
    <fileset dir="./">
        <include name="*.jar"/>
    </fileset>
</path>

<!-- Compiles all code in the current directory and append to the classpath -->
<target name="compile">
    <javac destdir="${src}" srcdir="${src}">
        <classpath refid="compile.classpath"/>
    </javac>
</target>

<!-- Runs the Test code with junit argument as long as compile was run previously -->
<target name="run" depends="compile">
    <java classname="Tests" fork="true">
        <arg value="${junit}"/>
    </java>
</target>

我的JUnit測試在Tests類中,我需要使用

java org.junit.runner.JUnitCore Tests

但是基於以下輸出,我相信它被稱為

java Tests org.junit.runner.JUnitCore

Ant-詳細輸出:

run:
     [java] Executing '/usr/lib/jvm/java-6-sun-1.6.0.26/jre/bin/java' with arguments:
     [java] 'Tests'
     [java] 'org.junit.runner.JUnitCore'
     [java] 
     [java] The ' characters around the executable and arguments are
     [java] not part of the command.
     [java] Exception in thread "main" java.lang.NoSuchMethodError: main
     [java] Java Result: 1

有任何想法嗎? 我一直在做研究,但是找不到很多關於參數的順序,特別是使用Java調用。 謝謝!

您已經調換了參數(即Tests )和主類org.junit.runner.JUnitCore

<arg>是程序的參數<jvmarg>是JVM的參數

在這兩者之間,您將擁有主班。

Java用法:

用法:java [-options]類[args ...]

在您的情況下,您想執行org.junit.runner.JUnitCore的main方法,並且傳遞給該main方法的參數應該是Tests

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM