Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

[junit] java.lang.ClassNotFoundException HELP!!!!!!!

807580Dec 2 2009 — edited Dec 4 2009
Hello,

I'm trying to get my project running with my ant build.xml file but i get the following error:

Buildfile: C:\Users\bmesta\Desktop\workspace\Project2\build.xml
compile:
testApplication:
[echo] Running the junit tests...
[junit] Testsuite: project2.AllTests
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Null Test: Caused an ERROR
[junit] project2.AllTests
[junit] java.lang.ClassNotFoundException: project2.AllTests
[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:276)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
[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:247)
[junit] at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[junit] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[junit] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
[junit] Test project2.AllTests FAILED
all:
BUILD SUCCESSFUL
Total time: 546 milliseconds

My build file is the following:
<project name="Project2" default="all" basedir=".">
	<description>
		Simple build file
	</description>	
	<!-- set global properties for this build -->
	<property name="sourceDir" location="src" />
	<property name="testDir" location="test" />
	<property name="junitLocation" value="C:/Program Files/eclipse/plugins/org.junit4_4.3.1/junit.jar" />		
	<path id="classpath">
	    <pathelement location="${junitLocation}" />
	</path>	
	<target name="clean-compile-test">
		<delete verbose="false">
			<fileset dir="${testDir}" includes="**/*.class" />
		</delete>
	</target>	
	<!-- Compile the java code from ${src} -->	
	<target name="compile" description="compile the source" >
		<javac srcdir="${sourceDir}" verbose="false" debug="true"/>
	</target>	
	<target name="testApplication" depends="compile">
		<echo>Running the junit tests...</echo>
		<junit>
			<classpath refid="classpath" />
			<formatter type="brief" usefile="false" />
			<batchtest>
				<fileset dir="${testDir}" includes="**/*Tests.class" />
			</batchtest>
		</junit>
	</target>		
	<target name="all" depends="testApplication" />
	<target name="clean" depends="clean-compile-test" />
</project>
FYI, the structure of my project is the following:

Project2
-src
-project2 [package]
GSTCalc.java, GSTCalcMain.java, GSTCalcPanel.java, GSTCalcFrame.java
-test
-project2 [package]
GSTCalcTest.java, GSTCalcPanelTest.java, GSTCalcFrameTest.java, and AllTests.java

I can't fix this problem for some reason it cant find my AllTests class. If you can hel fix this problem I will be so happy. Im so frustrated and I need to get this working. Btw, this is my first build file that i have wrote.

Cheers,

BRUNO
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 1 2010
Added on Dec 2 2009
7 comments
1,786 views