I am new in Java, spent on this problem too much time, can’t solve it:
I run build.xml file in Eclipse Java project. Project successfully built, all tests passed, but after that project not working, seems to be that something wrong happens with .classpath file, cause if I change build path settings (e.g. delete libs and add again), everything works…
build.xml file
`
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="src" />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dist" />
<property name="test.report.dir" location="test report" />
<!-- Define the classpath which includes -->
<path id="junit.class.path">
<!-- needed libs -->
<pathelement location="lib/commons-dbcp.jar" />
<pathelement location="lib/commons-logging.jar" />
<pathelement location="lib/commons-pool.jar" />
<pathelement location="lib/log4j-1.2.15.jar" />
<pathelement location="lib/mysql-connector-java-5.1.6-bin.jar" />
<pathelement location="lib/spring.jar" />
<pathelement location="lib/spring-webmvc.jar" />
<pathelement location="lib/standard.jar" />
<!-- JUnit 3-4 -->
<pathelement location="C:\Program Files\eclipse\plugins\org.junit_4.8.1.v4_8_1_v20100427-1100\junit.jar" />
<pathelement location="C:\Program Files\eclipse\plugins\org.junit_3.8.2.v3_8_2_v20100427-1100\junit.jar" />
<!-- repository-config.xml -->
<pathelement location="config" />
<!-- classes after compiling -->
<pathelement location="${build.dir}" />
</path>
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
<delete dir="${test.report.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${build.dir}" />
<mkdir dir="${dist.dir}" />
<mkdir dir="${test.report.dir}" />
</target>
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" depends="clean, makedir">
<javac srcdir="${src.dir}" destdir="${build.dir}">
<classpath refid="junit.class.path" />
</javac>
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile">
<jar destfile="${dist.dir}\empdb.build.ant.jar" basedir="${build.dir}">
</jar>
</target>
<!-- Run the JUnit Tests -->
<!-- Output is XML, could also be plain-->
<target name="junit" depends="jar">
<junit printsummary="on" fork="true" haltonfailure="yes">
<classpath refid="junit.class.path" />
<formatter type="xml" />
<batchtest todir="${test.report.dir}">
<fileset dir="${src.dir}">
<include name="**/*Test*.java" />
</fileset>
</batchtest>
</junit>
</target>
<target name="main" depends="junit">
<description>Main target</description>
</target>
`
This is the error on one of tests after project build
Class not found sef.test.repository.StubProjectRepositoryImplTest
java.lang.ClassNotFoundException: sef.test.repository.StubProjectRepositoryImplTest
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Often eclipse flips out when files changes.
Try this.