Announcement Announcement Module
Collapse
No announcement yet.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver - maven Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • java.lang.ClassNotFoundException: com.mysql.jdbc.Driver - maven

    Hi,
    I've created a new spring3+hibernate eclipse project using maven 3.

    It was running fine with inbuilt sql. I have added the mysql dependency as follows

    Code:
    <dependency>
    	<groupId>mysql</groupId>
    	<artifactId>mysql-connector-java</artifactId>
    	<version>5.1.10</version>
    </dependency>
    When I run the test target of maven, it is completed successfully.

    Code:
    INFO : org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
    INFO : org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider - Using provided datasource
    INFO : org.hibernate.cfg.SettingsFactory - Database ->
           name : MySQL
        version : 5.5.27
          major : 5
          minor : 5
    INFO : org.hibernate.cfg.SettingsFactory - Driver ->
           name : MySQL-AB JDBC Driver
        version : mysql-connector-java-5.1.10 ( Revision: ${svn.Revision} )
          major : 5
          minor : 1
    INFO : org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
    INFO : org.hibernate.engine.jdbc.JdbcSupportLoader - Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
    INFO : org.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
    INFO : org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    Code:
    INFO : org.hibernate.tool.hbm2ddl.TableMetadata - table found: license_prod_2.person
    INFO : org.hibernate.tool.hbm2ddl.TableMetadata - columns: [id, lastname, firstname]
    INFO : org.hibernate.tool.hbm2ddl.TableMetadata - foreign keys: []
    INFO : org.hibernate.tool.hbm2ddl.TableMetadata - indexes: [primary]
    INFO : org.hibernate.tool.hbm2ddl.SchemaUpdate - schema update complete
    INFO : org.springframework.test.context.transaction.TransactionalTestExecutionListener - Began transaction (1): transaction manager [org.springframework.orm.jpa.JpaTransactionManager@23d275]; rollback [true]
    Hibernate: insert into Person (firstName, lastName) values (?, ?)
    Hibernate: insert into Person (firstName, lastName) values (?, ?)
    Hibernate: insert into Person (firstName, lastName) values (?, ?)
    Hibernate: select person0_.id as id0_, person0_.firstName as firstName0_, person0_.lastName as lastName0_ from Person person0_
    INFO : org.springframework.test.context.transaction.TransactionalTestExecutionListener - Rolled back transaction after test execution for test context [[TestContext@1e2c841 testClass = PersonControllerTest, locations = array<String>['classpath:/test-context.xml'], testInstance = org.grassfield.crm4.controller.PersonControllerTest@1c958af, testMethod = shouldReturnPersonListView@PersonControllerTest, testException = [null]]]
    INFO : org.springframework.test.context.transaction.TransactionalTestExecutionListener - Began transaction (2): transaction manager [org.springframework.orm.jpa.JpaTransactionManager@23d275]; rollback [true]
    Hibernate: insert into Person (firstName, lastName) values (?, ?)
    Hibernate: insert into Person (firstName, lastName) values (?, ?)
    Hibernate: insert into Person (firstName, lastName) values (?, ?)
    Hibernate: select person0_.id as id0_0_, person0_.firstName as firstName0_0_, person0_.lastName as lastName0_0_ from Person person0_ where person0_.id=?
    INFO : org.springframework.test.context.transaction.TransactionalTestExecutionListener - Rolled back transaction after test execution for test context [[TestContext@1e2c841 testClass = PersonControllerTest, locations = array<String>['classpath:/test-context.xml'], testInstance = org.grassfield.crm4.controller.PersonControllerTest@1453d72, testMethod = shouldReturnSecondPersonWithEditMav@PersonControllerTest, testException = [null]]]
    Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.328 sec
    
    Results :
    
    Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
    
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 8.109s
    [INFO] Finished at: Tue Oct 23 10:59:07 BST 2012
    [INFO] Final Memory: 4M/15M
    [INFO] ------------------------------------------------------------------------
    But when I run the application on Tomcat using Run on Server option, it shows ClassNotFoundException

    Code:
    WARN : org.hibernate.ejb.Ejb3Configuration - Defining hibernate.transaction.flush_before_completion=true ignored in HEM
    WARN : org.hibernate.cfg.SettingsFactory - Could not obtain connection to query metadata
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Unknown Source)
    	at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:657)
    	at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:430)
    	at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:71)
    	at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:114)
    	at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2833)
    	at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2829)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
    	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902)
    	at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
    	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
    	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4765)
    	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5260)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1525)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1515)
    	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    	at java.util.concurrent.FutureTask.run(Unknown Source)
    	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)
    ERROR: org.hibernate.tool.hbm2ddl.SchemaUpdate - could not get database metadata
    Am I doing something wrong in tomcat config?
Working...
X