views:

431

answers:

2

I have a Java project in Eclipse perfectly running smoothly until this afternoon, when I updated some files (including a ant build.xml file). When I build the project, the following error appears:

java.lang.NoClassDefFoundError: proj/absa/FrontEnd/ApplicationStarter
Caused by: java.lang.ClassNotFoundException: proj.absa.FrontEnd.ApplicationStarter
    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)  
Exception in thread "main" 

Does anyone have a clue where the problem may be?

+1  A: 

java.lang.ClassNotFoundException means CLASSPATH issues. Not having a clue implies that you're assuming that the CLASSPATH is set properly, but it's not.

If you're building with Eclipse, make sure that the directory where your compiled .class files exists, is in the CLASSPATH, and has the necessary .class files in it.

If you're building with Ant, make sure you see something like this in your build.xml:

<path id="production.class.path">
    <pathelement location="${production.classes}"/>
    <pathelement location="${production.resources}"/>
    <fileset dir="${production.lib}">
        <include name="**/*.jar"/>
        <exclude name="**/junit*.jar"/>
        <exclude name="**/*test*.jar"/>
    </fileset>
</path>

UPDATE: Either you don't have JAVA_HOME/bin in your PATH or you downloaded the JRE instead of the JDK. Check the directory where you installed Java and see if your /bin directory has javac.exe in it. If you don't have a /bin, download the JDK and install it.

If you do have a /bin with javac.exe in it, check your PATH to see that the Java /bin directory is in the PATH. Once you've set it, open a command shell and type "javac -version" to ensure that all is well.

What JDK did you tell Eclipse to use?

duffymo
everything seems to be fine. I have just noticed that if I build the build.xml file it fails and the following error is displayed: `Error running javac.exe compiler` pointing at this line of the build file:`<javac srcdir="${src.dir}/${FrontEnd.dir}" destdir="${classes.dir}" classpathref="master-classpath" fork="yes">` It seems the compiler is missing, do you think that the previous error is related to this one? Many thanks!
Tony
I did set the JAVA_HOME/bin variable to the bin folder where the javac.exe file is contained (it's jdk 1.6.0_18). In the Install JRE section of Eclipse I did add the jdk 1.6.0_18, so everything seems to be set perfectly. One thing I have noticed (and I don't know if it's relevant or not) is that in the Properties dialog of the project, in the "Java Compiler" section, the "Use Compliance from the Execution Environment on the java Build Path" is always disabled and can't be enabled, while in the other projects this problem doesn't exist....thanks for the help!
Tony
A: 

both the problem will be because of classpathref="master-classpath", please check the value is correct

sreejith
so do you think it would be better to remove the `classpathref="master-classpath` from the build file and create a classpath variable in Eclipse?
Tony
please check this for the first problem for the second problem Error running javac.exe compiler pointing at this line of the build file: <javac srcdir="${src.dir}/${FrontEnd.dir}" destdir="${classes.dir}" classpathref="master-classpath" fork="yes"> there is less chance that javac will not be there... the problem may be because some other parameters are wrong, so configure class path in eclipse and give the statement like this <javac srcdir="${src.dir}/${FrontEnd.dir}" destdir="${classes.dir}">
sreejith