You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Michele Perrotta <mi...@cabel.it> on 2012/04/05 15:26:09 UTC

mysql db pool and NoClassDefFoundError

Hi all,

I premise that I am approached to the apache Geronimo/Tomcat world only 
recently and I don't know much details about those servers.


Ok, now here's my problem:

On Geronimo 2.2.1 + Tomcat6  I create a mysql database pool via the wizard 
in order to connect a war to my mysql db.
I used mysql-connector-java-5.1.12-bin.jar as driver (or connector?).

I also, as described in the "usage" link of the pool (on the console), 
added to the war the geronimo-web.xml file.


web.xml:
============================================

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
 
<servlet>
        <servlet-name>Extractor</servlet-name>
        <servlet-class>database.Extractor</servlet-class>
</servlet>
 
<servlet-mapping>
        <servlet-name>Extractor</servlet-name>
        <url-pattern>/Extractor</url-pattern>
</servlet-mapping>
 
<session-config>
        <session-timeout>30</session-timeout>
</session-config>
 
<resource-ref>
        <res-ref-name>mysqlpool</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope> 
</resource-ref>
 
</web-app>

============================================



geronimo-web.xml:
============================================

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1">
 
        <environment>
 
                <moduleId>
                        <artifactId>TestPool2</artifactId>
                </moduleId>
 
                <dependencies>
                        <dependency>
                                <groupId>console.dbpool</groupId>
                                <artifactId>jdbc_local_mysql</artifactId>
                        </dependency>
                </dependencies>
 
        </environment>

        <context-root>/TestPool2</context-root>

        <resource-ref>
                <ref-name>mysqlpool</ref-name>
                <resource-link>jdbc/local_mysql</resource-link>
        </resource-ref>
 
</web-app>

============================================



Servlet:
============================================

...

InitialContext ctx = new InitialContext();
 
String resourcename = "mysqlpool";
 
DataSource ds = (DataSource) ctx.lookup("java:comp/env/"+resourcename);
 
con = ds.getConnection();
 
String sql = "select message from log.mito_logbook limit 10";
PreparedStatement pstm = con.prepareStatement(sql);
 
ResultSet rs = pstm.executeQuery();
 
while(rs.next())
{
        out.println("<p>"+rs.getString(1)+"</p>");
}

...

============================================


After the war deploy (no problems with it), I tried to run the application 
and I got the following (Extractor is the name of my servlet):

ERROR [[Extractor]] Servlet.service() for servlet Extractor threw 
exception java.lang.NoClassDefFoundError: 
org/apache/tomcat/jdbc/pool/DataSource

        at database.Extractor.processRequest(Extractor.java:50)
        at database.Extractor.doGet(Extractor.java:104)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
        at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at 
org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.invoke(GeronimoStandardContext.java:420)
        at 
org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(GeronimoBeforeAfterValve.java:47)
        at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at 
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)
        at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
        at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at 
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:396)
        at org.apache.geronimo.pool.ThreadPool$1.run(ThreadPool.java:214)
        at 
org.apache.geronimo.pool.ThreadPool$ContextClassLoaderRunnable.run(ThreadPool.java:344)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown 
Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown 
Source)
        at java.lang.Thread.run(Unknown Source)



I really don't know what's going on.
Well it's a "No Class Definition", but I cannot understand, the mysql 
connector (the jar I mentioned above) doesn't provide the tomcat jdbc 
DataSource class too?

I am missing some basic connector-related concepts?


--
Michele.


AVVERTENZE:  Il presente messaggio e/o i suoi allegati (di seguito il "messaggio") possono contenere informazioni privilegiate e/o confidenziali. Se non siete i destinatari indicati nel messaggio (o persona incaricata di inoltrare il messaggio al/i destinatario/i), non potete copiare o inoltrare il messaggio ad altri e siete invitati a distruggerlo dandone informazione al mittente a mezzo e-mail. Il contenuto del presente messaggio non deve essere considerato come trasmesso o autorizzato da Cabel. Cabel non si assume alcuna responsabilit� per eventuali intercettazioni, modifiche o danneggiamenti del presente messaggio e-mail e per le eventuali conseguenze. DISCLAIMER:  Privileged/Confidential Information may be contained in this message and in any of its attachments (the "message"). If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message and kindly notify the sender by reply e-mail. The contents of this message shall be understood as neither given nor endorsed by Cabel. Cabel does not accept liability for corruption, interception or amendment, if any, or the consequences thereof. 

Rif: Re: mysql db pool and NoClassDefFoundError

Posted by Michele Perrotta <mi...@cabel.it>.
Well.
This is embarrassing.

I was importing the org.apache.tomcat.jdbc.pool.DataSource
.
Once I've imported javax.sql.Datasource all worked as expected.

Thank you very much.





Da:     Ivan <xh...@gmail.com>
Per:    user@geronimo.apache.org
Data:   2012-04-05 16:15
Oggetto:        Re: mysql db pool and NoClassDefFoundError



Think that the servlet  Extractor did not import the correct DataSource 
class.

2012/4/5 Michele Perrotta <mi...@cabel.it>
Hi all,

I premise that I am approached to the apache Geronimo/Tomcat world only 
recently and I don't know much details about those servers.


Ok, now here's my problem:

On Geronimo 2.2.1 + Tomcat6  I create a mysql database pool via the wizard 
in order to connect a war to my mysql db.
I used mysql-connector-java-5.1.12-bin.jar as driver (or connector?).

I also, as described in the "usage" link of the pool (on the console), 
added to the war the geronimo-web.xml file.


web.xml:
============================================

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    
<servlet>
        <servlet-name>Extractor</servlet-name>
        <servlet-class>database.Extractor</servlet-class>
</servlet>
        
<servlet-mapping>
        <servlet-name>Extractor</servlet-name>
        <url-pattern>/Extractor</url-pattern>
</servlet-mapping>
        
<session-config>
        <session-timeout>30</session-timeout>
</session-config>
        
<resource-ref>
        <res-ref-name>mysqlpool</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>                
</resource-ref>
        
</web-app>

============================================



geronimo-web.xml:
============================================

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1">
        
        <environment>
                
                <moduleId>
                        <artifactId>TestPool2</artifactId>
                </moduleId>
                
                <dependencies>
                        <dependency>
                                <groupId>console.dbpool</groupId>
                                <artifactId>jdbc_local_mysql</artifactId>
                        </dependency>
                </dependencies>
                
        </environment>

        <context-root>/TestPool2</context-root>

        <resource-ref>
                <ref-name>mysqlpool</ref-name>
                <resource-link>jdbc/local_mysql</resource-link>
        </resource-ref>
        
</web-app>

============================================



Servlet:
============================================

...

InitialContext ctx = new InitialContext();
                                
String resourcename = "mysqlpool";
                                
DataSource ds = (DataSource) ctx.lookup("java:comp/env/"+resourcename);
                                
con = ds.getConnection();
                                
String sql = "select message from log.mito_logbook limit 10";
PreparedStatement pstm = con.prepareStatement(sql);
                                
ResultSet rs = pstm.executeQuery();
                                
while(rs.next())
{
        out.println("<p>"+rs.getString(1)+"</p>");
}

...

============================================


After the war deploy (no problems with it), I tried to run the application 
and I got the following (Extractor is the name of my servlet):

ERROR [[Extractor]] Servlet.service() for servlet Extractor threw 
exception java.lang.NoClassDefFoundError: 
org/apache/tomcat/jdbc/pool/DataSource

        at database.Extractor.processRequest(Extractor.java:50)
        at database.Extractor.doGet(Extractor.java:104)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
        at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at 
org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.invoke(GeronimoStandardContext.java:420)
        at 
org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(GeronimoBeforeAfterValve.java:47)
        at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at 
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)
        at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
        at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at 
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:396)
        at org.apache.geronimo.pool.ThreadPool$1.run(ThreadPool.java:214)
        at 
org.apache.geronimo.pool.ThreadPool$ContextClassLoaderRunnable.run(ThreadPool.java:344)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown 
Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown 
Source)
        at java.lang.Thread.run(Unknown Source)



I really don't know what's going on.
Well it's a "No Class Definition", but I cannot understand, the mysql 
connector (the jar I mentioned above) doesn't provide the tomcat jdbc 
DataSource class too?

I am missing some basic connector-related concepts?


--
Michele.

AVVERTENZE: Il presente messaggio e/o i suoi allegati (di seguito il 
"messaggio") possono contenere informazioni privilegiate e/o 
confidenziali. Se non siete i destinatari indicati nel messaggio (o 
persona incaricata di inoltrare il messaggio al/i destinatario/i), non 
potete copiare o inoltrare il messaggio ad altri e siete invitati a 
distruggerlo dandone informazione al mittente a mezzo e-mail. Il contenuto 
del presente messaggio non deve essere considerato come trasmesso o 
autorizzato da Cabel. Cabel non si assume alcuna responsabilità per 
eventuali intercettazioni, modifiche o danneggiamenti del presente 
messaggio e-mail e per le eventuali conseguenze.
DISCLAIMER: Privileged/Confidential Information may be contained in this 
message and in any of its attachments (the "message"). If you are not the 
addressee indicated in this message (or responsible for delivery of the 
message to such person), you may not copy or deliver this message to 
anyone. In such case, you should destroy this message and kindly notify 
the sender by reply e-mail. The contents of this message shall be 
understood as neither given nor endorsed by Cabel. Cabel does not accept 
liability for corruption, interception or amendment, if any, or the 
consequences thereof.



-- 
Ivan

AVVERTENZE:  Il presente messaggio e/o i suoi allegati (di seguito il "messaggio") possono contenere informazioni privilegiate e/o confidenziali. Se non siete i destinatari indicati nel messaggio (o persona incaricata di inoltrare il messaggio al/i destinatario/i), non potete copiare o inoltrare il messaggio ad altri e siete invitati a distruggerlo dandone informazione al mittente a mezzo e-mail. Il contenuto del presente messaggio non deve essere considerato come trasmesso o autorizzato da Cabel. Cabel non si assume alcuna responsabilità per eventuali intercettazioni, modifiche o danneggiamenti del presente messaggio e-mail e per le eventuali conseguenze. DISCLAIMER:  Privileged/Confidential Information may be contained in this message and in any of its attachments (the "message"). If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message and kindly notify the sender by reply e-mail. The contents of this message shall be understood as neither given nor endorsed by Cabel. Cabel does not accept liability for corruption, interception or amendment, if any, or the consequences thereof. 

Re: mysql db pool and NoClassDefFoundError

Posted by Ivan <xh...@gmail.com>.
Think that the servlet  Extractor did not import the correct DataSource
class.

2012/4/5 Michele Perrotta <mi...@cabel.it>

> Hi all,
>
> I premise that I am approached to the apache Geronimo/Tomcat world only
> recently and I don't know much details about those servers.
>
>
> Ok, now here's my problem:
>
> On Geronimo 2.2.1 + Tomcat6  I create a mysql database pool via the wizard
> in order to connect a war to my mysql db.
> I used mysql-connector-java-5.1.12-bin.jar as driver (or connector?).
>
> I also, as described in the "usage" link of the pool (on the console),
> added to the war the geronimo-web.xml file.
>
>
> web.xml:
> ============================================
>
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
> http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
>
> <servlet>
>         <servlet-name>Extractor</servlet-name>
>         <servlet-class>database.Extractor</servlet-class>
> </servlet>
>
> <servlet-mapping>
>         <servlet-name>Extractor</servlet-name>
>         <url-pattern>/Extractor</url-pattern>
> </servlet-mapping>
>
> <session-config>
>         <session-timeout>30</session-timeout>
> </session-config>
>
> <resource-ref>
>         <res-ref-name>mysqlpool</res-ref-name>
>         <res-type>javax.sql.DataSource</res-type>
>         <res-auth>Container</res-auth>
>         <res-sharing-scope>Shareable</res-sharing-scope>
> </resource-ref>
>
> </web-app>
>
> ============================================
>
>
>
> geronimo-web.xml:
> ============================================
>
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1">
>
>         <environment>
>
>                 <moduleId>
>                         <artifactId>TestPool2</artifactId>
>                 </moduleId>
>
>                 <dependencies>
>                         <dependency>
>                                 <groupId>console.dbpool</groupId>
>                                 <artifactId>jdbc_local_mysql</artifactId>
>                         </dependency>
>                 </dependencies>
>
>         </environment>
>
>         <context-root>/TestPool2</context-root>
>
>         <resource-ref>
>                 <ref-name>mysqlpool</ref-name>
>                 <resource-link>jdbc/local_mysql</resource-link>
>         </resource-ref>
>
> </web-app>
>
> ============================================
>
>
>
> Servlet:
> ============================================
>
> ...
>
> InitialContext ctx = new InitialContext();
>
> String resourcename = "mysqlpool";
>
> DataSource ds = (DataSource) ctx.lookup("java:comp/env/"+resourcename);
>
> con = ds.getConnection();
>
> String sql = "select message from log.mito_logbook limit 10";
> PreparedStatement pstm = con.prepareStatement(sql);
>
> ResultSet rs = pstm.executeQuery();
>
> while(rs.next())
> {
>         out.println("<p>"+rs.getString(1)+"</p>");
> }
>
> ...
>
> ============================================
>
>
> After the war deploy (no problems with it), I tried to run the application
> and I got the following (Extractor is the name of my servlet):
>
> ERROR [[Extractor]] Servlet.service() for servlet Extractor threw
> exception java.lang.NoClassDefFoundError:
> org/apache/tomcat/jdbc/pool/DataSource
>
>         at database.Extractor.processRequest(Extractor.java:50)
>         at database.Extractor.doGet(Extractor.java:104)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
>         at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
>         at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>         at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
>         at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
>         at
> org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.invoke(GeronimoStandardContext.java:420)
>         at
> org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(GeronimoBeforeAfterValve.java:47)
>         at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
>         at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>         at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)
>         at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>         at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
>         at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
>         at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
>         at
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:396)
>         at org.apache.geronimo.pool.ThreadPool$1.run(ThreadPool.java:214)
>         at
> org.apache.geronimo.pool.ThreadPool$ContextClassLoaderRunnable.run(ThreadPool.java:344)
>         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown
> Source)
>         at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown
> Source)
>         at java.lang.Thread.run(Unknown Source)
>
>
>
> I really don't know what's going on.
> Well it's a "No Class Definition", but I cannot understand, the mysql
> connector (the jar I mentioned above) doesn't provide the tomcat jdbc
> DataSource class too?
>
> I am missing some basic connector-related concepts?
>
>
> --
> Michele.
>
> **
>
> AVVERTENZE: Il presente messaggio e/o i suoi allegati (di seguito il
> "messaggio") possono contenere informazioni privilegiate e/o confidenziali.
> Se non siete i destinatari indicati nel messaggio (o persona incaricata di
> inoltrare il messaggio al/i destinatario/i), non potete copiare o inoltrare
> il messaggio ad altri e siete invitati a distruggerlo dandone informazione
> al mittente a mezzo e-mail. Il contenuto del presente messaggio non deve
> essere considerato come trasmesso o autorizzato da Cabel. Cabel non si
> assume alcuna responsabilità per eventuali intercettazioni, modifiche o
> danneggiamenti del presente messaggio e-mail e per le eventuali conseguenze.
>
> DISCLAIMER: Privileged/Confidential Information may be contained in this
> message and in any of its attachments (the "message"). If you are not the
> addressee indicated in this message (or responsible for delivery of the
> message to such person), you may not copy or deliver this message to
> anyone. In such case, you should destroy this message and kindly notify the
> sender by reply e-mail. The contents of this message shall be understood as
> neither given nor endorsed by Cabel. Cabel does not accept liability for
> corruption, interception or amendment, if any, or the consequences thereof.
>



-- 
Ivan