将java编译的文件作为参数传递给ant目标

时间:2016-04-10 07:25:33

标签: java ant

我试图使用Daikon来测试一个大型项目,所以我需要ant来编译并为我运行一切。由于我是蚂蚁的新手,我试图通过给予Daikon的一个简单例子来熟悉它。因此,最佳候选示例是与Daikon相关联的StackAr包。

要正常运行Daikon,我将在编译所有我定位的java文件后执行以下命令。

java daikon.Chicory --daikon DataStructures.StackArTester

等同于此命令

java -cp "/usr/lib/daikonparent/daikon-5.2.20/daikon.jar:." daikon.Chicory --daikon DataStructures.StackArTester

这两个命令将使用带有daikon.jar标记的Chicory接口运行--daikon,并将StackArTester.class对其进行检测并运行它。

现在,我尝试使用ant运行相同的命令如下所示:

<project name="StackAr" default="compile" basedir=".">
  <description>
    simple example build file
  </description>
  <!-- set global properties for this build -->
  <property name="src" location="DataStructures"/>
  <property name="build" location="DataStructures"/>

  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
  </target>

  <target name="compile" depends="init"
        description="compile the source">
    <!-- Compile the java code from ${src} into ${build} -->
    <javac  srcdir="${src}" 
            destdir="."
            debug="on"
    />
  </target>

  <target name="run" description="run StackArTester">
      <java classname="DataStructures.StackArTester">
         <classpath>
             <pathelement location="."/>
         </classpath>
      </java>
  </target>

  <target name="inv" description="run daikon">
      <java classname="daikon.Chicory" >
         <arg value="--daikon" />
         <arg value="DataStructures.StackArTester"/>
         <classpath>
             <pathelement path="/usr/lib/daikonparent/daikon-5.2.20/daikon.jar"/>
         </classpath>
      </java>
  </target>

  <target name="clean"
        description="clean up">
    <!-- Delete the ${build} and ${dist} directory trees -->
  </target>
</project>

目标compile用于编译所有源文件并且正在运行。此外,目标run用作测试以运行目标.class文件并且正在运行。目标inv是我遇到麻烦的地方,它假设等同于上面的两个命令。

我的问题是,我不确定我是怎么想将.calss文件传递给Daikon的。从结果我看到我肯定第一个参数/标志--daikon被识别出来。然而,对于我的大多数轮胎中的第二个参数DataStructures.StackArTester,我发现它已被认可,但是Daikon的类路径存在问题。运行ant inv上面的脚本将生成以下错误消息:

Buildfile: /usr/lib/daikonparent/daikon-5.2.20/examples/java-examples/StackAr/build.xml

inv:
     [java] 
     [java] Executing target program: java -cp /usr/share/ant/lib/ant-launcher.jar:/usr/lib/daikonparent/daikon-5.2.20/daikon.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-7-openjdk-amd64/lib/tools.jar:/usr/share/ant/lib/ant-testutil.jar:/usr/share/ant/lib/ant-apache-log4j.jar:/usr/share/ant/lib/ant-javamail.jar:/usr/share/ant/lib/ant-jsch.jar:/usr/share/ant/lib/ant-apache-regexp.jar:/usr/share/ant/lib/ant-antlr.jar:/usr/share/ant/lib/ant-swing.jar:/usr/share/ant/lib/ant-apache-oro.jar:/usr/share/ant/lib/ant-apache-bcel.jar:/usr/share/ant/lib/ant-apache-xalan2.jar:/usr/share/ant/lib/ant-junit.jar:/usr/share/ant/lib/ant-launcher.jar:/usr/share/ant/lib/ant-apache-bsf.jar:/usr/share/ant/lib/ant-jdepend.jar:/usr/share/ant/lib/ant-apache-resolver.jar:/usr/share/ant/lib/ant-jmf.jar:/usr/share/ant/lib/ant-commons-logging.jar:/usr/share/ant/lib/ant-commons-net.jar:/usr/share/ant/lib/ant-junit4.jar:/usr/share/ant/lib/ant.jar:/usr/lib/jvm/java-7-openjdk-amd64/lib/tools.jar -ea -Xmx1000m -javaagent:/usr/lib/daikonparent/daikon-5.2.20/java/ChicoryPremain.jar=--daikon --dtrace-file=StackArTester.dtrace.gz DataStructures.StackArTester
     [java] entered daikon.chicory.Runtime.setDtrace(./StackArTester.dtrace.gz, false)...
     [java] Error: Could not find or load main class DataStructures.StackArTester
     [java] Chicory warning: No methods were instrumented.
     [java] Warning: Did not run Daikon because target exited with 1 status
     [java] Java Result: 1

BUILD SUCCESSFUL
Total time: 0 seconds

请注意错误是

Error: Could not find or load main class DataStructures.StackArTester

我想出了我可能尝试的想法。希望上面的信息足够了。请注意,执行原始命令和ant命令时,我在同一目录中。

Thakns ......

0 个答案:

没有答案