0

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

0

2 Answers 2

1

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.
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, thanks a lot @Mark O'connor ... But now i got struck with another error. [javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:79: error: method findCell in interface Sheet cannot be applied to given types; [javac] Cell tableEnd= sheet.findCell(tableName, startCol+1,startRow+1, 100, 64000, false); [javac] ^ [javac] required: String [javac] found: String,int,int,int,int,boolean [javac] reason: actual and formal argument lists differ in length [javac] 1 error
@Sakthivel That's a new question. Without more details looks like you're calling a method with the wrong parameter types.
0

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

1 Comment

I have added all the jar files in the basedir/lib location. i checked once again too. For org.testng.annotations.BeforeTest, its corresponding testng-5.0.jar is also there in the LIB folder inside the project

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.