Hey guys, 

I have a question about the classloader... 

When reading the following message, please keep in the back of your mind 
that my application does NOT reside in the default webapps directory... 

I created my own virtual host, with its context in a location like 
/var/www/mywebapp.  I don't think this should matter, but it might... 

Also, please excuse the html tags...I tried to post this to another board, 
and I am just plain tired of writing and wasting 5 hours today trying to 
solve this problem. 


Message: 

<p>Hey all,</p> 

<p>I have a problem that is driving me nuts...and I'm an experienced Tomcat 
user, so this is killing me.</p> 

<p>I'm using Tomcat 4.0.3 LE / jdk 1.4.0-b92</p> 

<p>Tomcat cannot find classes I place in a package, yet if I remove the 
package statement from the file, and just move the file to 
mywebapp/WEB-INF/classes, then tomcat can find it.</p> 

<p>when I place the .java file in the proper package directory with the 
cooresponding package statement in the file, and I try to run my webapp, 
tomcat throws an InstantiationException.</p> 

<p>I then went to the actual translated jsp page turned into servlet (the 
mypage$jsp.java file Tomcat generates) and find that the error is not really 
an InstantiationException...its a ClassNotFoundException. i.e., the 
mypage$jsp.java file just catches the ClassNotFoundException and then 
immediately throws the InstantiationException.</p> 

<p>So now I know that Tomcat can't find the file, not just that it can't 
instantiate it...but I'm baffled, because the file is in the correct 
place.</p> 

<p>This is the setup:</p> 

<p>my compiled class (DatabaseWrapper class) is located in:<br>
mywebapp/WEB-INF/classes/com/leshazlewood/cs4400/util/DatabaseWrapper.class< 
/p> 

<p>the package statement IN (and the 1st line) of this file is:<br>
package com.leshazlewood.cs4400.util;</p> 

<p>When in this structure, Tomcat throws the ClassNotFoundException.</p> 

<p>When I take it out of the package, and move it to WEB-INF/classes, Tomcat 
finds and instantiates the class just fine.</p> 

<p>For your convenience, I've included the java class file WITH the package 
statement included.  This is how it is SUPPOSED to be, and how I would like 
it.  This is then followed by Tomcat's error page output.</p> 

<p>MANY Thanks in advance!!!</p> 

<p>Les</p> 

<hl>
<center>Java Code Follows:</center>
<p>
<pre>
package com.leshazlewood.cs4400.util; 

import java.sql.*;
import java.util.*;
import java.io.*;
import com.javaexchange.dbConnectionBroker.*; 

/** A singleton class for wrapping the database for access by other 
application tiers.
*  Also implements connection pooling.
*
* @author  Les A. Hazlewood
* @version 0.1, 11/03/01
*/ 

public class DatabaseWrapper
{
   protected static DbConnectionBroker connBroker     = null;
   protected static boolean            conPoolReady = false; 

   public DatabaseWrapper(){} 

   public static void initConPool()
   {
       try
       { 

           connBroker = new DbConnectionBroker(Constants.DB_DRIVER,
                                               Constants.DB_JDBC_STRING,
                                               Constants.DB_USERNAME,
                                               Constants.DB_PASSWORD,
                                               Constants.DB_POOL_MIN_CONS,
                                               Constants.DB_POOL_MAX_CONS,
                                               Constants.DB_POOL_LOG_FILE,
                                              
Constants.DB_POOL_MAX_CON_TIME);
           conPoolReady = true;
       }
       catch (IOException ioe){}
   } 

   public static synchronized Connection getConnection()
   {
       Connection conn; 

       if (!conPoolReady)
           initConPool(); 

       conn = connBroker.getConnection(); 

       return conn; 

   } //ends getConnection() 

   public static synchronized void closeConnection(Connection conn)
   {
       try
       {
           //don't actually close it...put it back in the pool:
           if (conn != null)
           {
               //some beans may have turned off autocommit...so
               //turn it back on here so other beans that use it
               //will have the default behavior:
               conn.setAutoCommit(true); 

               connBroker.freeConnection(conn);
           }
       }
       catch (Exception e)
       {
           e.printStackTrace();
       }
   } 

}// ends class DatabaseWrapper
</pre>
</p> 

<hl>
<center>Tomcat's Error Page Output Follows:</center>
<p>
<pre>
javax.servlet.ServletException: DatabaseWrapper
        at 
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImp 
l.java:463)
        at org.apache.jsp.custMembApp$jsp._jspService(custMembApp$jsp.java:374)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at 
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.ja 
va:202)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application 
FilterChain.java:247)
        at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh 
ain.java:193)
        at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja 
va:243)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5 
66)
        at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja 
va:190)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5 
66)
        at 
org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:2 
46)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5 
64)
        at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at 
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
        at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180 
)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5 
66)
        at 
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve. 
java:170)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5 
64)
        at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170 
)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5 
64)
        at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java 
:174)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5 
66)
        at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at 
org.apache.catalina.connector.warp.WarpRequestHandler.handle(WarpRequestHand 
ler.java:217)
        at 
org.apache.catalina.connector.warp.WarpConnection.run(WarpConnection.java:19 
4)
        at java.lang.Thread.run(Thread.java:536) 


root cause 

java.lang.InstantiationException: DatabaseWrapper
        at org.apache.jsp.custMembApp$jsp._jspService(custMembApp$jsp.java:86)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at 
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.ja 
va:202)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application 
FilterChain.java:247)
        at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh 
ain.java:193)
        at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja 
va:243)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5 
66)
        at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja 
va:190)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5 
66)
        at 
org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:2 
46)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5 
64)
        at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at 
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
        at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180 
)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5 
66)
        at 
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve. 
java:170)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5 
64)
        at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170 
)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5 
64)
        at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java 
:174)
        at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:5 
66)
        at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
        at 
org.apache.catalina.connector.warp.WarpRequestHandler.handle(WarpRequestHand 
ler.java:217)
        at 
org.apache.catalina.connector.warp.WarpConnection.run(WarpConnection.java:19 
4)
        at java.lang.Thread.run(Thread.java:536)
</pre>
</p>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to