aspose file tools*
The moose likes Beginning Java and the fly likes package and classpath confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package and classpath confusion" Watch "package and classpath confusion" New topic
Author

package and classpath confusion

Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

I have a class called stringHandler.class
(package us.mn.state.dnr.jomica.general
My file system is like this:
.....\webapps\lite\WEB-INF\classes\lite\jomica\general\stringHandler.class
How can I set my classpath so that it can find this package?
Here is my shotgun approach to the classpath setting:
.....\webapps\lite\WEB-INF\classes\;
.....\webapps\lite\WEB-INF\classes\lite\;
.....\webapps\lite\WEB-INF\classes\lite\jomica\general\stringHandler.class
.....\webapps\lite\WEB-INF\classes\lite\jomica\general\;
.....\webapps\lite\WEB-INF\classes\lite.jar;
but I always get the following apache error:
java.lang.NoClassDefFoundError: us/mn/state/dnr/jomica/general/stringHandling
followed by a whole page of insults.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Tim,
Welcome to JavaRanch. I'm guessing that this is a web application and you are trying to use the class in a JSP or Servlet. Whether that is the case or not, as the ClassLoader is so rudely telling you, there must be a directory structure of <classPathDirectory>/us/mn/state/dnr/jomica/general/ somewhere in the CLASSPATH and stringHandler.class must be located there. The package syntax must match the directory structure so since the fully qualified name of your class is us.mn.state.dnr.jomica.general.stringHandler then you must have the above directory. If you are trying to access the file from the context directory of a web application then you should have a directory of <contextDirectory>/WEB-INF/classes/us/mn/state/dnr/jomica/general/ and that is where stringHandler.class should be.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

That is what I thought too, but on the development server (maintained by someone else) does not have <context>/classes/WEB-INF/us/mn/state/dnr/jomica/general directory anywhere and things are working O.K. there.
I will check in with the jokers who run the server tomorrow.
In order to maintain and test the webapp, I am copying it to my desktop and this is where I am running into the error.
But I still am confounded by packages.
Take the following code:
package JavaStuff;
public class Circle
{
public static void main(String args[])
{
System.out.println("All Circles are round");
}
}
this compiles in folder JavaStuff
but does not run. Instead I get: NoClassDefFoundError: Circle (wrong name: JavaStuff/Circle)
If I understood that, I could move forward.
Thanks for your help!
[ May 08, 2003: Message edited by: Tim McGuire ]
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
It runs fine on my machine. Did you invoke it like this:

That won't work. Try this:
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821

Originally posted by Tim McGuire:
That is what I thought too, but on the development server (maintained by someone else) does not have <context>/classes/WEB-INF/us/mn/state/dnr/jomica/general directory anywhere and things are working O.K. there.

Is this package located in a .jar file? Look in the .jar files located in <context>/WEB-INF/lib to see if the package is located there.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
jQuery in Action, 2nd edition
 
subject: package and classpath confusion