Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difficulty in executing

 
renu richard
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
Error
------------
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
om/example/Sample)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
4)
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
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try changing to this directory

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

and running > java com.example.Sample
 
renu richard
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ande...It Worked!!!
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic