Hi M M You can compile any .java file with "javac". By default, the .class generated file is stored in the same directory as the original .java file.
For e.g.: > cd E:\workspace\pkg\src > javac hellp.java ... or, with the same results: > javac E:\workspace\pkg\src Both "javac" commands produce the file *E:\workspace\pkg\src*\/hello.class/ But when executing the .class file things are different. The .class file "knows" it belongs to the package "haaa". It means the path "haaa/hello.class" must be found in one of the classpath entries For e.g.: > java -cp E:\workspace\pkg\src haaa.hello ... will wok only if the compiled file is *E:\workspace\pkg\src\*haaa\/hello.class/ So, in order to get working, it is a good idea to store files in directory tree-like hierarchy according to the packages (NetBeans and Eclipse automatically take care of this). For e.g.: -- put your file in *E:\workspace\pkg\src*\haaa -- compile it like: > cd E:\workspace\pkg\src > javac haaa\hello.java -- execute it like: > java -cp *E:\workspace\pkg\src* haaa.hello Hope it helps mihai M M a écrit : > I have a java file named hello.java which is given below:- > > package haaa; > class hello > { > public static void main(String [] args) > { > System.out.println("Hello"); > } > } > > > I am using Windows XP. In my system, CLASSPATH is set to "E:\workspace > \pkg\src". Initially, the file is present in the folder "E:\workspace > \pkg\src\". When I tried to compile it, there was no error. But when I > tried to execute the command, > > java haaa.hello > > then it returned an error like this:- > > Exception in thread "main" java.lang.NoClassDefFoundError: haaa/hello > > Caused by: java.lang.ClassNotFoundException: haaa.hello > 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 java.lang.ClassLoader.loadClassInternal(Unknown Source) > Could not find the main class: haaa.hello. Program will exit. > > Could you please help me correct the error. > > Also, my system has a Linux OS. In Linux OS, whenever I compile and > execute java programs in Eclipse IDE, then it goes smoothly. But when > I try to compile in terminal using javac command then it tells that > "no such command found". For setting PATH variable in Linux, I need to > know where javac file is located. But I searched everywhere in Linux > using File Search facility. So, why is there a difference between > Eclipse IDE and terminal? I need your help desperately. > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en -~----------~----~----~----~------~----~------~--~---