This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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
Joined: Apr 03, 2001
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).]
Joined: Sep 29, 2000
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.
Joined: Apr 03, 2001
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).]