Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package and classpath confusion

 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It runs fine on my machine. Did you invoke it like this:

That won't work. Try this:
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic