Problem in finding java class file

I am writting an application using servlets , JSP and a simple java classfile. The simple java class file is for connection pool and the name of connection pool class is DBConnectionManager . I am using JavaWebserver2.0 and I have placed this class file in .\JavaWebserver2.0\classes

I am placing my servlets in .\JavaWebserver2.0\servlets folder. Since I am using wfm package so my servlets are placed in .\JavaWebserver2.0\servlets\wfm .

The problem is with compiling the servlet placed in wfm folder . I get the following error:-

TestServlet.java:11:cannot resolve symbol

symbol: class DBConnectionManager

location: class wfm.TestServlet

However when I try to compile this class in servlets folder and remove the package statement from the source file, it compiles and works very fine. I am having lot of confusion as the class DBConnectionManager is in classpath but even then compiler gives error. The same class when placed in servlets folder and package statement is removed works very fine.

Kindly help.

[1082 byte] By [javahunt] at [2007-9-26 1:59:06]
# 1
Awaiting help from someone Thanks in anticipation
javahunt at 2007-6-29 3:17:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi !!

Your problem is very easily solved !! Here is the solution :-

1. First of all set your java classpath with an entry like this : set classpath=%classpath%;c:\javawebserver2.0\classes\;.;

(The Dot is useful for detecting classes in the same folder)

This will help the JVM to detect that DBConnectionManager.class file is in the the right folder.

2. You can compile your servlet like this (from command prompt) if u dont want to fiddle around with the system classpath.

c:\JavaWebServer2.0\> javac servlets\wfm\*.java -classpath "%classpath%;c:\javawebserver2.0\classes;."

3. Now You shouldnt have any problem. Finally check the result at http://localhost:8080/servlet/wfm.<Your-Servlet-Name>

4. Now u can use this class straightaway without any qualification inside ur servlet program :

eg: DBConnectionManager dbConn=new DBConnectionManager();

Hope this helps ....

Happy Programming !!

Chandu

chandu_9 at 2007-6-29 3:17:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Hi Chandu,

Thanks for taking out your time and efforts but the problem still persists.

Class path is not the problem I have given . and all other possible directories in classpath. I have even placed the DBConnectionManager class in servlets directory even then it is not being compiled.

I would appreciate your help

Thanks

harpreet_hira at 2007-6-29 3:17:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Hi,Is the DBConnectionManager class declared public?Does the TestServlet import the package that contains the DBConnectionManager?This is all I can come up with, with the current information.Cheers, --Arnout
ajkuiper at 2007-6-29 3:17:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

hi,

where ru compiling ur servlet file from? if ur compiling it from the wfm foler itself, then it wont be able to find the package. u need to move one level up, i.e. in the servlets folder (wfm folder is in servlets folder, isnt it), and then compile the java code as:

javac wfm.testservlet.java

this problem comes when we use packages. we cannot compile from the package (wfm) itself.

hope this helps...

keep programming...

-satyen

filtertipped at 2007-6-29 3:17:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...