运行build.xml文件时出错

时间:2014-04-23 13:19:33

标签: java xml ant

我是ANT版本的新手,我在尝试运行下面提到的Build文件时遇到了一些错误。我已经在lib文件夹中添加了所有jar文件。但我仍然面临着这些错误。我想我在类路径区域做了一些其他的错误。

这是build.xml

<project name="ant_testing" default="compile" basedir=".">

  <property name="jar" value="${basedir}/classes"/>
  <property name="lib" value="${basedir}/lib"/>
  <property name="src" value="${basedir}/src"/>
  <property name="classes" value="${basedir}/classes"/>

  <target name="setClassPath" unless="test.classpath">
    <path id="testcompile">
      <pathelement location="${jar}"/>
      <fileset dir="${lib}">
        <include name="*.jar"/>
      </fileset>
    </path>
  </target>

  <target name="compile" depends="setClassPath">
    <javac includeantruntime="false" srcdir="${src}" destdir="${classes}" includes="**/*.java" listfiles="yes"/>
    <classpath refid="testcompile"/>
  </target>

  <target name="run" depends="compile">
    <java>
      <classpath path="classes"/>
    </java>
  </target>

</project>

这是错误列表

Buildfile: D:\sakthi\JUNIT\ant_testing\build.xml
setClassPath:
compile:
[javac] Compiling 1 source file to D:\sakthi\JUNIT\ant_testing\classes
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:3: error: package org.testng.annotations does not exist
[javac] import org.testng.annotations.BeforeClass;
[javac]                              ^
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:4: error: package org.testng.annotations does not exist
[javac] import org.testng.annotations.BeforeSuite;
[javac]                              ^
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:5: error: package org.testng.annotations does not exist
[javac] import org.testng.annotations.BeforeTest;
[javac]                              ^
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:6: error: package org.testng.annotations does not exist
[javac] import org.testng.annotations.DataProvider;
[javac]                              ^
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:7: error: package org.testng.annotations does not exist
[javac] import org.testng.annotations.Test;
[javac]                              ^
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:8: error: package com.thoughtworks.selenium does not exist
[javac] import com.thoughtworks.selenium.SeleneseTestBase;
[javac]                                 ^
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:12: error: package jxl does not exist
[javac] import jxl.*;
[javac] ^
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:14: error: cannot find symbol
[javac] public class ant_testing extends SeleneseTestBase{
[javac]                                  ^
[javac]   symbol: class SeleneseTestBase
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:18: error: cannot find symbol
[javac]     @BeforeSuite
[javac]      ^
[javac]   symbol:   class BeforeSuite
[javac]   location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:29: error: cannot find symbol
[javac]     @BeforeTest     
[javac]      ^
[javac]   symbol:   class BeforeTest
[javac]   location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:45: error: cannot find symbol
[javac]     @DataProvider(name = "DP1")
[javac]      ^
[javac]   symbol:   class DataProvider
[javac]   location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:53: error: cannot find symbol
[javac]     @Test (dataProvider = "DP1")
[javac]      ^
[javac]   symbol:   class Test
[javac]   location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:74: error: cannot find symbol
[javac]             Workbook workbook = Workbook.getWorkbook(new File(xlFilePath));
[javac]             ^
[javac]   symbol:   class Workbook
[javac]   location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:74: error: cannot find symbol
[javac]             Workbook workbook = Workbook.getWorkbook(new File(xlFilePath));
[javac]                                 ^
[javac]   symbol:   variable Workbook
[javac]   location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:75: error: cannot find symbol
[javac]             Sheet sheet = workbook.getSheet(sheetName);
[javac]             ^
[javac]   symbol:   class Sheet
[javac]   location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:77: error: cannot find symbol
[javac]             Cell tableStart=sheet.findCell(tableName);
[javac]             ^
[javac]   symbol:   class Cell
[javac]   location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:80: error: cannot find symbol
[javac]             Cell tableEnd= sheet.findCell(tableName, startCol+1,startRow+1, 100, 64000,  false);              
[javac]             ^
[javac]   symbol:   class Cell
[javac]   location: class ant_testing
[javac] 17 errors

BUILD FAILED
D:\sakthi\JUNIT\ant_testing\build.xml:19: Compile failed; see the compiler error output for details.
Total time: 611 milliseconds

帮我解决这个问题:(。 在此先感谢:)

2 个答案:

答案 0 :(得分:1)

你的编译器在它的classpath上没有jar。以下是您宣布javac任务的方式:

<javac includeantruntime="false" srcdir="${src}" destdir="${classes}" includes="**/*.java" listfiles="yes"/>

尝试以下简化的构建文件:

<project name="ant_testing" default="compile" basedir=".">

  <property name="build.dir"   location="build"/>
  <property name="lib.dir"     location="lib"/>
  <property name="src.dir"     location="src"/>
  <property name="classes.dir" location="${build.dir}/classes"/>

  <path id="compile.path">
    <fileset dir="${lib.dir}" includes="*.jar"/>
  </path>

  <target name="compile">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="compile.path" includeantruntime="false"/>
  </target>

  <target name="run" depends="compile">
    <java .. ..>
      <classpath>
        <path refid="compile.path"/>
        <pathelement location="${classes.dir}"/>
      </classpath>
    </java>
  </target>
</project>

注意:

  • 编译在顶部声明的类路径以及其他项目,如属性
  • 属性使用“location”属性。专为文件路径名设计
  • Javac任务使用classpathref接受它的classpath
  • Java任务有一个classpath元素,由现有路径和目录文件元素组成。

答案 1 :(得分:0)

你没有org.testng.annotations.BeforeTest in classpath的jar。只是双重检查jar在构建阶段的类路径中(取决于你正在执行哪个蚂蚁目标)。我猜你的情况是${basedir}/lib