Exception in thread "main" java.lang.NoClassDefFoundError

Exception in thread "main" java.lang.NoClassDefFoundError

Exception in thread "main" java.lang.NoClassDefFoundError

A friend of mine wanted to start to learn java, and I wanted to help him, so we created a simple Hello World example.

public class Hello {
    public static void main(String argv[]) {
        System.out.println("Hello world !");
    } 
}

then, when you compile it:

javac Hello.java

and want to execute it:

java Hello

Exception in thread "main" java.lang.NoClassDefFoundError: Hello

We set the CLASSPATH and JAVA_HOME enviroment variable correctly, and the problem was still the same..

When we copied the Hello.class into a lib directory of JAVA_HOME, it worked, but not from the current directory !

We tried different versions of java.. and do you know where this stupid problem is?

in the CLASSPATH there should be: CLASSPATH=.;c:\programme\jboss\lib;c:\programme\ j2sdk1.4.2_08\lib;c:\programme\j2sdk1.4.2_08\jre\lib; ...

yes.. a dot .. it means, that it will search for classes bytecode in the current directory !

you can also tell java to search the current directory with the -classpath parameter

java -classpath . Hello

Problems like this can really discourage java newbies, and that moment was very embarassing :)

Problem:

Basically, the Exception in thread "main" java.lang.NoClassDefFoundError:

means, that the class which you are trying to run was not found in the classpath.

Solution:

you need to add the class or .jar file which contains this class into the java classpath. When you are running a java class from the command line, you need to add the dot (.)

java YourSingleClass -cp . 

into the classpath which tells the JVM to search for classes in actual directory.

If you are running a class from a .jar file, you need to add this jar file into the classpath:

java org.somepackage.SomeClass -cp myJarWithSomeClass.jar

Related Posts



188BET - LINK 188BET CASINO sitemap sbobet asia royal online mobile link vao sbobet m88 slot Slotpantip freeslots W88
www.thedancecloset.net| www.locksmithdecaturga.net| www.michaelgraphicsinc.com| www.raydennisonchevy.net| www.seacruisersvlogs.com| www.defeatmsbLog.com| www.zhaoyiqiao.com| www.systematic-course.com| www.jayscheesesteak.net| www.desenwiremesh.com| www.fastfifa14.net| www.lamaisondeaces.com| www.bestjackandcoke.com| www.dfwl.org| www.fourwindshomes.com| www.bluewhaleonline.com| www.amazingnewstar.com| www.az-sunnah.com| www.buLduktrans.net| www.petcareconsultant.com| www.americanmooncake.com| www.exclusivetouch.net| www.w88wsports.net| www.desenwiremesh.com| www.theonlycurefor.com| www.oz3bkkf.cn| www.bijouxpopulaire.com| www.cetidmed.com| www.longfarwiremesh.com| www.francisorphe.com| www.angieciarimboli.com| www.avcomprojecson.com| www.desiredirectory.com| www.onlinew88th.com| www.apprenticereview.com| www.andrewheimann.com| www.dominica-hotel.com| www.elandiecasting.com| www.komunitasbunda.com| www.heyitsnollie.com| www.siliconheavy.com| www.thefitnesspreneur.com|