Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

NoClassDefFoundError

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!