开发者

Can't find mysql.jdbc.Driver - MySQL, JBoss

I'm unable to deploy my web app with MySQL 5.5.11 backend to JBoss 5. I get this error:

Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from BaseClassLoader@262b2310

I pasted my stack trace below.

Here's what I've done...

I added mysql-connector-java-5.1.14-bin.jar to {JBOSS_HOME}/lib (that connector should work with MySQL 5.5.11 right?). I also added mysql-ds.xml to {JBOSS_HOME}/server/default/deploy.

<datasources> 
    <local-tx-datasource> 
        <jndi-name>MySqlDS</jndi-name> 
        <connection-url>jdbc:mysql://localhost:3306/my_libl_db</connection-url> 
        <driver-class>com.mysql.jdbc.Driver</driver-class> 
        <user-name>root</user-name> 
        <password>test</password>
        <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
    </local-tx-datasource> 
</datasources> 

Also, I made sure the mysql-connector-java-5.1.14-bin.jar in my lib folder is in my web apps classpath. In the JBoss Admin Console, under Resources/Datasources, I do see MySqlDS with a status of up.

My project (in Eclipse Indego Release) is an Enterprise Application Project with 1 Dynamic Web Project. The web app has has an @Entity bean and a @Stateless bean. The @Stateless is being injected to a servlet (using @EJB). Here's my persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
    <persistence-unit name="ContactBookPersistUnit" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider> 
        <jta-data-source>java:/MySqlDS</jta-data-source>
        <class>com.contact.model.Contact</class>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
        </properties>
    </persistence-unit>
</persistence>

What could I be doing wrong?

Caused by: javax.resource.ResourceException: Unable to get managed connection for MySqlDS
    at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:441)
    at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:381)
    at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:496)
    at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:941)
    at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:89)
    ... 65 more
Caused by: org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Failed to register driver for: com.mysql.jdbc.Driver; - nested throwable: (java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from BaseClassLoader@262b2310{VFSClassLoaderPolicy@5a0b0303{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ domain=ClassLoaderDomain@5e33f929{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ parentPolicy=AFTER_BUT_JAVA_BEFORE parent=BaseClassLoader@7cdd93a5{vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/}} roots=[ZipEntryHandler@150136868[path=ContactBook.ear/ContactBookWeb.war/WEB-INF/classes context=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ real=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/WEB-INF/classes]]  delegates=null exported=[, com.contact.servlet, com.contact.service, com.contact.model, com.contact.control, META-INF] <IMPORT-ALL>NON_EMPTY}}))
    at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:225)
    at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:195)
    at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:633)
    at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:267)
    at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:622)
    at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:404)
    ... 69 more
Caused by: org.jboss.resource.JBossResourceException: Failed to register driver for: com.mysql.jdbc.Driver; - nested throwable: (java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from BaseClassLoader@262b2310{VFSClassLoaderPolicy@5a0b0303{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ domain=ClassLoaderDomain@5e33f929{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ parentPolicy=AFTER_BUT_JAVA_BEFORE parent=BaseClassLoader@7cdd93a5{vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/}} roots开发者_如何学运维=[ZipEntryHandler@150136868[path=ContactBook.ear/ContactBookWeb.war/WEB-INF/classes context=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ real=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/WEB-INF/classes]]  delegates=null exported=[, com.contact.servlet, com.contact.service, com.contact.model, com.contact.control, META-INF] <IMPORT-ALL>NON_EMPTY}})
    at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getDriver(LocalManagedConnectionFactory.java:489)
    at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:206)
    ... 74 more
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from BaseClassLoader@262b2310{VFSClassLoaderPolicy@5a0b0303{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ domain=ClassLoaderDomain@5e33f929{name=vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/ parentPolicy=AFTER_BUT_JAVA_BEFORE parent=BaseClassLoader@7cdd93a5{vfszip:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/}} roots=[ZipEntryHandler@150136868[path=ContactBook.ear/ContactBookWeb.war/WEB-INF/classes context=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ real=file:/Users/Albert/DEV/Servers/JBoss5/server/default/deploy/ContactBook.ear/ContactBookWeb.war/WEB-INF/classes]]  delegates=null exported=[, com.contact.servlet, com.contact.service, com.contact.model, com.contact.control, META-INF] <IMPORT-ALL>NON_EMPTY}}
    at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:448)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getDriver(LocalManagedConnectionFactory.java:474)


This bit of documentation says you need to add the JAR to the /lib file in your default server configuration:

http://docs.jboss.org/jbossas/getting_started/v4/html/db.html

UPDATE: JBOSS 6 and newer has been rewritten to be more modular. You have to add JBDC drivers to your /module directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜