• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

NoClassDefFoundError

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a program that consists of 3 several classes. Each class begins with this statement:
package com.safeway.co.query;
All classes are in the same directory:
C:\Tomcat 4.1\webapps\meds\WEB-INF\classes\com\safeway\lcham02\query\
javac *.java completes normally.
BUT when I try to execute Main MedQB, I get the following:

C:\Tomcat 4.1\webapps\meds\WEB-INF\classes>java MedsQB
Exception in thread "main" java.lang.NoClassDefFoundError: MedsQB (wrong name: com/safeway/lcham02/query/MedsQB)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
I need to have these classes in a named package for my JSP, but I also want to be able to test them from the command line.
LC
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't the package name have to match the path? "com.safeway.lcham02.query"
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried changing your class directory to this?
C:\Tomcat 4.1\webapps\meds\WEB-INF\classes\com\safeway\co\query\
Angel
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're trying to run a class named MedsQB, but there is no such class. There is only a class named com.safeway.lcham02.query.MedsQB . So your first problem is that you have to use the real name of the class to invoke it.
Your second problem is that once you use the real name, Java won't think that MedsQB.class contains that class any more. It will expect to find a file named
com\safeway\lcham02\query\MedsQB.class -- i.e., it will translate the package name into a path name.
So cd into C:\Tomcat 4.1\webapps\meds\WEB-INF\classes, then type "java com.safeway.lcham02.query.MedsQB", and Java will find the class file and the "wrong name" error will disappear.
Now, if MedsQB has a main() method, it will be executed.
Why are you building applications under the Tomcat directory tree?
 
Luke Chambers
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm building under the Tomcat directory tree because the I'm building beans for use in JSP.. I only need to execute main() for debugging purposes.
Thanks for your help.
C:\Tomcat 4.1\webapps\meds\WEB-INF\classes\com\safeway\lcham02\query>java com.safeway.lcham02.query.MedsQB
Executes correctly.
 
Get me the mayor's office! I need to tell him about this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic