title: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in JBoss 7.1.1 - what is wrong?
body: <p>I have an application that has a datasource defined in context-common.xml and the details are loaded from my application.properties.</p>
  
  <p>I tried to follow this tutorial from jBoss <a href="https://community.jboss.org/wiki/DataSourceConfigurationInAS7" rel="nofollow">https://community.jboss.org/wiki/DataSourceConfigurationInAS7</a></p>
  
  <p>So I added the mysql-connector-java-5.1.22 in this structure /modules/com/mysql/main/ and I added a module.xml with it. It reads: </p>
  
  <p></p>
  
  <pre><code>&lt;resources&gt;
      &lt;resource-root path="mysql-connector-java-5.1.22.jar"/&gt;
      &lt;!-- Insert resources here --&gt;
  &lt;/resources&gt;
  &lt;dependencies&gt;
      &lt;module name="javax.api"/&gt;
  
  &lt;/dependencies&gt;
  </code></pre>
  
  <p></p>
  
  <p>And in my standalone.xml:</p>
  
  <pre><code>&lt;datasources&gt;
  &lt;datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true"&gt;
  
  &lt;connection-url&gt;jdbc:mysql://localhost:3306/cab;DB_CLOSE_DELAY=-1&lt;/connection-url&gt;
  &lt;driver&gt;mysql&lt;/driver&gt;
  &lt;security&gt;
  &lt;user-name&gt;root&lt;/user-name&gt;
  &lt;password&gt;root&lt;/password&gt;
  &lt;/security&gt;
  &lt;/datasource&gt;
  &lt;drivers&gt;
  &lt;driver name="mysql" module="com.mysql"&gt;
  &lt;xa-datasource-class&gt;com.mysql.jdbc.jdbc2.optional.MysqlXADataSource&lt;/xa-datasource-class&gt;
  &lt;/driver&gt;
  </code></pre>
  
  <p>I don't understand what I should do with the jndi-name? Do I even need it?I didn't use it when I was using JBoss 4. </p>
  
  <p>Also, here is some more of the stack trace:</p>
  
  <pre><code>10:00:23,338 WARN  [org.hibernate.util.JDBCExceptionReporter] (MSC service thread 1-2) SQL Error: 0, SQLState: null
  10:00:23,342 ERROR [org.hibernate.util.JDBCExceptionReporter] (MSC service thread 1-2) Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
  10:00:23,347 WARN  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-2) Could not obtain connection metadata: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
      at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136) [commons-dbcp-1.2.2.jar:1.2.2]
      at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) [commons-dbcp-1.2.2.jar:1.2.2]
      at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:83) [spring-orm-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84) [hibernate-3.2.7.ga.jar:3.2.7.ga]
      at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2090) [hibernate-3.2.7.ga.jar:3.2.7.ga]
      at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2086) [hibernate-3.2.7.ga.jar:3.2.7.ga]
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1311) [hibernate-3.2.7.ga.jar:3.2.7.ga]
      at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867) [hibernate-annotations-3.4.0.GA.jar:3.2.7.ga]
      at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:863) [spring-orm-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:782) [spring-orm-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188) [spring-orm-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:610) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) [spring-context-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) [spring-context-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) [spring-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) [spring-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
      at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
      at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
      at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
      at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_20]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_20]
      at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_20]
  Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from [Module "deployment.cab-1.0-SNAPSHOT.war:main" from Service Module Loader]
  </code></pre>