• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Difficulty in executing

 
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!!!
 
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!!!
 
Sheriff
Posts: 11343
Mac Safari Java
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!