jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Difficulty in executing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difficulty in executing" Watch "Difficulty in executing" New topic

Difficulty in executing

renu richard
Ranch Hand

Joined: Oct 06, 2008
Posts: 116
I am able to compile Sample.java file. But i could not run that class file. I am getting the below error when trying to execute.
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\srilanka\WEB-INF\
classes\com\example>java Sample
Exception in thread "main" java.lang.NoClassDefFoundError: Sample (wrong name: c
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

Sample.java is inside this package: com/example
I have set "C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\srilanka\WEB-INF\classes\com\example" in the classpath.
And when i am trying to execute it i am getting the above error.

Please help me in solving this. Many thanks!!!

dee anderson

Joined: Oct 10, 2008
Posts: 16
try changing to this directory

C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\srilanka\WEB-INF\

and running > java com.example.Sample
renu richard
Ranch Hand

Joined: Oct 06, 2008
Posts: 116
Thanks ande...It Worked!!!
marc weber

Joined: Aug 31, 2004
Posts: 11343

Originally posted by renu richard:
Thanks ande...It Worked!!!

But do you understand why this is needed?

The Sample class is part of the package "com.example." Therefore, its fully qualified class name is "com.example.Sample," and this is located in the "classes" directory.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link: http://aspose.com/file-tools
subject: Difficulty in executing
It's not a secret anymore!