aspose file tools*
The moose likes Beginning Java and the fly likes java.lang.NoClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.lang.NoClassDefFoundError" Watch "java.lang.NoClassDefFoundError" New topic
Author

java.lang.NoClassDefFoundError

Sanjay Anand
Ranch Hand

Joined: Apr 03, 2001
Posts: 42
Hi,
I am running servlets on Tomcat with Netscape ES 3.6 on Solaris.
I have been asked to put all my sql query generating methods in a single location and not in the local directory where the servlet sits.
How, then, can I get the servlet to call the required method from the appropriate class?
One solution I tried was to put the appropriate query-generating class in the classpath statement. But even that is not working and I am still getting the above-mentioned error.
Is there any other way?
Thanks in advance.
Sanjay Anand
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
packages. That is what they are all about.
We have our classpath pointing to \xx\xx\xx\myApp
Then in that directory we have myApp.jar
In this jar file there are lots of packages combined including
com.gm.myApp.gui
com.gm.myApp.gui.query
com.gm.myApp.sql
com.gm.myApp.util
etc.
This provides organization to the zillions of classes, and makes the API easier to navigate.
Each of these packages contains lots of classes. Each of the classes in the packages declares the package that it is in at the top.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Sanjay Anand
Ranch Hand

Joined: Apr 03, 2001
Posts: 42
Thanks for the reply Cindy. I've been reading and trying but I cannot get it to work.
This is what I did (makeQuery is the class I'm trying to refer to, custRowCounter is the class trying to use makeQuery methods):
1. placed makeQuery in /local/XYZ/java/sanjay/databasestuff, compiled it and made it into a 'jar' file using this command:
jar cf makeQuery.jar makeQuery.class
2. put "package abc.database;" at the top of makeQuery
3. put "/local/XYZ/java/sanjay/databasestuff" in classpath declaration.
4. put "import abc.database.makeQuery;" in the class that wants to use makeQuery methods.
But I'm getting this error:


Sanjay
[This message has been edited by Sanjay Anand (edited May 09, 2001).]
[This message has been edited by Sanjay Anand (edited May 09, 2001).]
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
When you make your jar file the class file has to actually be in the subdirectory structure that the package shows.
So the makeQuery class file need to be in
/local/XYZ/java/sanjay/databasestuff/abc/database/makeQuery.class
Your package declaration says abc.database and your import declaration says it is in msc.database.
Check these 2 things.
Sanjay Anand
Ranch Hand

Joined: Apr 03, 2001
Posts: 42
Thanks Cindy, I dug through the archive of questions and figured it out. And, as usual, you are right, you Java Goddess you!!
I changed the directory structure so that it became:
/local/XYZ/java/sanjay/database
I pointed the classpath to: /local/XYZ/java/sanjay/
I changed the import to: import database.makeQuery;
And, finally, put makeQuery in the database folder.
The 'abc' / 'msc' error was just in my posting the code because I was trying not to use the name of the company I am consulting for.
I guess importing custom packages seems to require a kind of 'overlap' of at least one level. Ah well, whatever works!
Thanks again.
Sanjay

[This message has been edited by Sanjay Anand (edited May 09, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.NoClassDefFoundError
 
Similar Threads
websphere 4.0 ..help needed ..pl ..very very urgent..
protected class?
Getting NPE !
Help, How much documentation is appropriate??
How to print a html page from Swings?