You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Ma...@emc.com on 2008/12/18 15:22:48 UTC

Ant Junit issues

I am fairly new to Ant and I am having issues with an ant script that I
am working on. I am receiving a ClassNotFoundException when the Junit
portion of my Ant script runs. The build and everything before that is
working correctly and the correct .class file is included in the class
path for the Junit portion. Is it possible to include a .class file to
the Junit classpath instead of a .jar? 

Thanks,
-Dan


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Ant Junit issues - CLASSPATH

Posted by Mark Salter <ma...@talktalk.net>.
Marshall_Daniel@emc.com wrote:
> Thank you Mark I will take a look. I caught and fixed the folder issue
> but It still is not finding the class. 

Did you change the classpath specification to remove the extra levels
into the junit task as well?

> If a class is called com.emc.elms.test.EMCLmcryptKeyGeneratorTest
> 
> then this class file might be found somewhere like:-
> 
> c:\Build
>    \build
>      \classes     	
>        \com
> 	 \emc
> 	   \elms
> 	     \test\EMCEMCLmcryptKeyGeneratorTest.class
> 
> To find this class, the java classpath would be :-
> 
>  <classpath>
> 	 <pathelement location="c:\Build\build\classes"/>
>  </classpath>
> 
> So in summary...
> 
> - you are specifying too deep a level of directory.
> 	Do a search for +java +classpath, I got :-
> 	      http://en.wikipedia.org/wiki/Classpath_(Java)
> 	Which also decribes class file placement relative to the
> 	 classpath folder
> - you are specifying src directories when perhaps only the classes ones
>    are needed.
> 


-- 
Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Ant Junit issues - CLASSPATH

Posted by Ma...@emc.com.
Thank you Mark I will take a look. I caught and fixed the folder issue
but It still is not finding the class. 

-Dan 

-----Original Message-----
From: Mark Salter [mailto:marksalter@talktalk.net] 
Sent: Thursday, December 18, 2008 2:00 PM
To: Ant Users List
Subject: Re: Ant Junit issues - CLASSPATH

Marshall_Daniel@emc.com wrote:
> Sure I can give you some of it. It looks like its dropping my source
> paths but I don't know why.
It is dropping directories called:-

   C:\Build\build\src\com\emc\elms\keygen
   C:\Build\build\src\com\emc\elms\test
   C:\Build\build\src\com\emc\elms\keygen
   C:\Build\build\src\com\emc\elms\test
   C:\Build\build\src\com\emc\elms\keygen
   C:\Build\build\src\com\emc\elms\test
   C:\Build\build\src\com\emc\elms\keygen
   C:\Build\build\src\com\emc\elms\test

as they do not exist?  You are compiling your src files into
c:\Build\build\classes, so you may find that c:\Build\build\src does not
exist on your machine?

I think your classpath for junit need only be :-

  <classpath>
	 <pathelement location="${classes.dir}"/>
 </classpath>

as that is where javac is placing your class files?  I assuming you are
compiling the EMCLmcryptKeyGeneratorTest.java into classes.dir?

If a class is called com.emc.elms.test.EMCLmcryptKeyGeneratorTest

then this class file might be found somewhere like:-

c:\Build
   \build
     \classes     	
       \com
	 \emc
	   \elms
	     \test\EMCEMCLmcryptKeyGeneratorTest.class

To find this class, the java classpath would be :-

 <classpath>
	 <pathelement location="c:\Build\build\classes"/>
 </classpath>

So in summary...

- you are specifying too deep a level of directory.
	Do a search for +java +classpath, I got :-
	      http://en.wikipedia.org/wiki/Classpath_(Java)
	Which also decribes class file placement relative to the
	 classpath folder
- you are specifying src directories when perhaps only the classes ones
   are needed.

-- 
Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Ant Junit issues - CLASSPATH

Posted by Mark Salter <ma...@talktalk.net>.
Marshall_Daniel@emc.com wrote:
> Sure I can give you some of it. It looks like its dropping my source
> paths but I don't know why.
It is dropping directories called:-

   C:\Build\build\src\com\emc\elms\keygen
   C:\Build\build\src\com\emc\elms\test
   C:\Build\build\src\com\emc\elms\keygen
   C:\Build\build\src\com\emc\elms\test
   C:\Build\build\src\com\emc\elms\keygen
   C:\Build\build\src\com\emc\elms\test
   C:\Build\build\src\com\emc\elms\keygen
   C:\Build\build\src\com\emc\elms\test

as they do not exist?  You are compiling your src files into
c:\Build\build\classes, so you may find that c:\Build\build\src does not
exist on your machine?

I think your classpath for junit need only be :-

  <classpath>
	 <pathelement location="${classes.dir}"/>
 </classpath>

as that is where javac is placing your class files?  I assuming you are
compiling the EMCLmcryptKeyGeneratorTest.java into classes.dir?

If a class is called com.emc.elms.test.EMCLmcryptKeyGeneratorTest

then this class file might be found somewhere like:-

c:\Build
   \build
     \classes     	
       \com
	 \emc
	   \elms
	     \test\EMCEMCLmcryptKeyGeneratorTest.class

To find this class, the java classpath would be :-

 <classpath>
	 <pathelement location="c:\Build\build\classes"/>
 </classpath>

So in summary...

- you are specifying too deep a level of directory.
	Do a search for +java +classpath, I got :-
	      http://en.wikipedia.org/wiki/Classpath_(Java)
	Which also decribes class file placement relative to the
	 classpath folder
- you are specifying src directories when perhaps only the classes ones
   are needed.

-- 
Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Ant Junit issues

Posted by Ma...@emc.com.
Sure I can give you some of it. It looks like its dropping my source
paths but I don't know why.

Here is the xml:

<!--Ant build file for EMCLmcryptKeyGenerator-->
<project name="EMCLmcryptKeyGenerator" basedir="C:/Build"
default="clean-compile-Lmcrypt">

	<property file="C:/Build/build.properties"/>
	
	<!--=========================Clean
Target========================-->
    <target name="clean-Lmcrypt">
        <delete dir="${build.dir}"/>
		<mkdir dir="${build.dir}"/>
    </target>
	

	<!--=========================Compile
Target========================-->
    <target name="compile-Lmcrypt" depends="clean-Lmcrypt">
        <mkdir dir="${classes.dir}"/>
        <javac source="1.5" target="1.5" nowarn="true"
srcdir="${src.dir}" destdir="${classes.dir}" debug="true"
deprecation="false">				
		<classpath>			
			<fileset dir="${latest.dir}">
				<include name="**/*.jar"/>
			</fileset>
		</classpath>
		</javac>
		<!--=========================Copy
Resources========================-->
		<copy todir="${classes.dir}">
			<fileset dir="${src.dir}" excludes="**/*.java"/>
		</copy>	
    </target>
	
	
	<!--=========================Run JUnit
Target========================-->	
	<target name="run-JUnit-Lmcrypt" description="Run JUnit tests
for EMCLmcryptKeyGenerator.java" depends="compile-Lmcrypt">
		<mkdir dir="${reports}"/>
		<junit printsummary="yes" haltonerror="yes"
haltonfailure="yes" fork="yes">
			<formatter type="plain" usefile="false"/>
			<test
name="com.emc.elms.test.EMCLmcryptKeyGeneratorTest"/>
			<classpath>
				<pathelement
location="${lmcrypt.src.dir}"/>
				<pathelement
location="${lmcrypt.test.src.dir}"/>
				<pathelement
location="${lmcrypt.class.dir}"/>
				<pathelement
location="${lmcrypt.test.class.dir}"/>
			</classpath>
		</junit>
	</target>
	
	<target name="clean-compile-Lmcrypt"
depends="clean-Lmcrypt,compile-Lmcrypt,run-JUnit-Lmcrypt"/>
	
</project>

Here is the properties file:
#This is the property file for build.xml. 
latest.dir=C:/Build/LatestVersion
src.dir=${latest.dir}/src
lib.dir=${latest.dir}/lib
build.dir=C:/Build/build
classes.dir=${build.dir}/classes
reports=${build.dir}/reports

#lmcrypt
lmcrypt.test.src.dir=C:/Build/LatestVersion/src/com/emc/elms/test
lmcrypt.src.dir=C:/Build/LatestVersion/src/com/emc/elms/keygen
lmcrypt.test.class.dir=C:/Build/build/src/com/emc/elms/test
lmcrypt.class.dir=C:/Build/build/src/com/emc/elms/keygen

Here is the output:

run-JUnit-Lmcrypt:
    [mkdir] Created dir: C:\Build\build\reports
    [junit] Found C:\Ant\lib\junit.jar
    [junit] Found C:\Ant\lib\ant-launcher.jar
    [junit] Found C:\Ant\lib\ant.jar
    [junit] Found C:\Ant\lib\ant-junit.jar
    [junit] Implicitly adding
C:\Ant\lib\junit.jar;C:\Ant\lib\ant-launcher.jar;C:\Ant\lib\ant.jar;C:\A
nt\lib\ant-junit.jar to CLASSPATH
dropping C:\Build\build\src\com\emc\elms\keygen from path as it doesn't
exist
dropping C:\Build\build\src\com\emc\elms\test from path as it doesn't
exist
dropping C:\Build\build\src\com\emc\elms\keygen from path as it doesn't
exist
dropping C:\Build\build\src\com\emc\elms\test from path as it doesn't
exist
dropping C:\Build\build\src\com\emc\elms\keygen from path as it doesn't
exist
dropping C:\Build\build\src\com\emc\elms\test from path as it doesn't
exist
dropping C:\Build\build\src\com\emc\elms\keygen from path as it doesn't
exist
dropping C:\Build\build\src\com\emc\elms\test from path as it doesn't
exist
    [junit] Executing 'C:\Program
Files\Java\jdk1.5.0_16\jre\bin\java.exe' with arguments:
    [junit] '-classpath'
    [junit]
'C:\Build\LatestVersion\src\com\emc\elms\keygen;C:\Build\LatestVersion\s
rc\com\emc\elms\test;C:\Ant\lib\junit.jar;C:\Ant\lib\ant-launcher.jar;C:
\Ant\lib\ant.jar;C:\Ant\lib\ant-junit.jar'
    [junit]
'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
    [junit] 'com.emc.elms.test.EMCLmcryptKeyGeneratorTest'
    [junit] 'filtertrace=true'
    [junit] 'haltOnError=true'
    [junit] 'haltOnFailure=true'
    [junit]
'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResu
ltFormatter'
    [junit] 'showoutput=false'
    [junit] 'outputtoformatters=true'
    [junit] 'logtestlistenerevents=true'
    [junit]
'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResult
Formatter'
    [junit] 'crashfile=C:\Build\junitvmwatcher257818702.properties'
    [junit] 'propsfile=C:\Build\junit1503989364.properties'
    [junit] 
    [junit] The ' characters around the executable and arguments are
    [junit] not part of the command.
Execute:Java13CommandLauncher: Executing 'C:\Program
Files\Java\jdk1.5.0_16\jre\bin\java.exe' with arguments:
'-classpath'
'C:\Build\LatestVersion\src\com\emc\elms\keygen;C:\Build\LatestVersion\s
rc\com\emc\elms\test;C:\Ant\lib\junit.jar;C:\Ant\lib\ant-launcher.jar;C:
\Ant\lib\ant.jar;C:\Ant\lib\ant-junit.jar'
'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
'com.emc.elms.test.EMCLmcryptKeyGeneratorTest'
'filtertrace=true'
'haltOnError=true'
'haltOnFailure=true'
'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResu
ltFormatter'
'showoutput=false'
'outputtoformatters=true'
'logtestlistenerevents=true'
'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResult
Formatter'
'crashfile=C:\Build\junitvmwatcher257818702.properties'
'propsfile=C:\Build\junit1503989364.properties'

The ' characters around the executable and arguments are
not part of the command.
    [junit] Running com.emc.elms.test.EMCLmcryptKeyGeneratorTest
    [junit] Testsuite: com.emc.elms.test.EMCLmcryptKeyGeneratorTest
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
    [junit] 
    [junit] 	Caused an ERROR
    [junit] com.emc.elms.test.EMCLmcryptKeyGeneratorTest
    [junit] java.lang.ClassNotFoundException:
com.emc.elms.test.EMCLmcryptKeyGeneratorTest
    [junit] 	at
java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    [junit] 	at java.security.AccessController.doPrivileged(Native
Method)
    [junit] 	at
java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    [junit] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    [junit] 	at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    [junit] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    [junit] 	at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    [junit] 	at java.lang.Class.forName0(Native Method)
    [junit] 	at java.lang.Class.forName(Class.java:164)
    [junit]  

-----Original Message-----
From: Mark Salter [mailto:marksalter@talktalk.net] 
Sent: Thursday, December 18, 2008 9:54 AM
To: Ant Users List
Subject: Re: Ant Junit issues

Marshall_Daniel@emc.com wrote:
> I am fairly new to Ant and I am having issues with an ant script that
I
> am working on. I am receiving a ClassNotFoundException when the Junit
> portion of my Ant script runs.
Is the missing class one of yours?

> The build and everything before that is
> working correctly and the correct .class file is included in the class
> path for the Junit portion.
CLASSPATHs don't hold class files directly, instead a list of locations
in which class files may be found...

> Is it possible to include a .class file to
> the Junit classpath instead of a .jar? 
Can you show us your junit task xml and perhaps the full stacktrace you
got?

-- 
Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Ant Junit issues

Posted by Mark Salter <ma...@talktalk.net>.
Marshall_Daniel@emc.com wrote:
> I am fairly new to Ant and I am having issues with an ant script that I
> am working on. I am receiving a ClassNotFoundException when the Junit
> portion of my Ant script runs.
Is the missing class one of yours?

> The build and everything before that is
> working correctly and the correct .class file is included in the class
> path for the Junit portion.
CLASSPATHs don't hold class files directly, instead a list of locations
in which class files may be found...

> Is it possible to include a .class file to
> the Junit classpath instead of a .jar? 
Can you show us your junit task xml and perhaps the full stacktrace you got?

-- 
Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org