Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError  RSS feed

 
Luke Chambers
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
 
Dan Walin
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"
 
Angel Dobbs-Sciortino
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
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!