简体   繁体   中英

Error while running build.xml file

I am new to ANT build and i'm facing some errors while trying to run this below mentioned Build file. I have added all the jar files in the lib folder. But still i'm facing those error. I guess i have made some other error in classpath area.

Here is 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>

here is the error list

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

Help me to resolve this issue :( . Thanks in advance :)

Your compile has not jars on it's classpath. Here's how you declared the javac task:

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

Try the following simplified build file:

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

Notes:

  • Compile class path declared at the top alongside other items like properties
  • Properties use the "location" attribute. Designed for file pathnames
  • Javac task uses classpathref to accept it's classpath
  • Java task has a classpath element, made up of an existing path and directory file pathelement.

You don't have jar which have org.testng.annotations.BeforeTest in classpath . Just double check jar is in classpath in build phase (Depends upon which ant goal you are executing) or not. which I guess in your case is ${basedir}/lib

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM