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
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?
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