I’m trying to execute unit tests using Ant. However, I am getting the error “package does not exist” even though I have included the classpath of the package.
Folder Structure in Eclipse
MyProject
- src
- com.project.core
- MyApp.java
- lib (contains all jar files and class files)
UnitTests
- src
- com.project.core.tests
- MyAppTest.java
- lib (contains all jar files)
- build.xml
build.xml
<?xml version="1.0"?>
<project name="Learning TestNG" basedir="." default="build">
<property name="src.dir" value="C:/UnitTests/src/com/Project/core/tests/"/>
<property name="build.dir" value="build"/>
<property name="src.jars" value="C:/MyProject/lib"/>
<property name="unit.test.jars" value="C:/UnitTests/lib"/>
<!--Define classpath -->
<path id="master-classpath">
<fileset dir="${src.jars}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${unit.test.jars}">
<include name="**/*.jar"/>
</fileset>
</path>
<!--Print out path -->
<pathconvert pathsep="${line.separator}| |-- "
property="echo.path.compile"
refid="master-classpath">
</pathconvert>
<echo>${echo.path.compile}</echo>
<!-- Main Build -->
<target name="build" description="Compile source tree java files">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" source="1.7" target="1.7" debug="on" includeantruntime="false" >
<classpath refid="master-classpath"/>
<src path="${src.dir}"/>
</javac>
</target>
</project>
Error
[javac] Compiling 1 source file to C:/UnitTests/build
[javac] C:\MyProject\src\com\project\core\MyApp.java:14: error: package com.project.example does not exist
[javac] import com.project.example.AddNumbers;
I need to understand why I am getting this error when I am setting the the classpath to .class file correctly? I have tried everything. Perhaps this is an Ant issue?