Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting a MySQL database to Glassfish classpath is not set or classname is wrong

I'm swapping out a derby database for a MySQL one. I had everything working before but after what I thought was the proper configuration I'm getting the error:

Caused by: javax.resource.ResourceException: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource

Full error output from console:

Caused by: javax.resource.ResourceException: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource
at com.sun.gjc.common.DataSourceObjectBuilder.getDataSourceObject(DataSourceObjectBuilder.java:292)
at com.sun.gjc.common.DataSourceObjectBuilder.constructDataSourceObject(DataSourceObjectBuilder.java:114)
at com.sun.gjc.spi.ManagedConnectionFactory.getDataSource(ManagedConnectionFactory.java:1292)
at com.sun.gjc.spi.DSManagedConnectionFactory.getDataSource(DSManagedConnectionFactory.java:148)
at com.sun.gjc.spi.DSManagedConnectionFactory.createManagedConnection(DSManagedConnectionFactory.java:101)
at com.sun.enterprise.resource.allocator.LocalTxConnectorAllocator.createResource(LocalTxConnectorAllocator.java:87)

I've double checked some of the names, the connection pool and other resources.I've also added the MySQL driver .jars to the library of glassfish in both projects. The database was definitely working correctly through eclipse because I was able to view tables and display the resources inside the database context of eclipse. So I know that at least THOSE drivers are working correcly. Also the persistence.xml file looks good. it references the jdbc/mydatabase jndi reference like it should and default JTA is selected as the manament type.

Does anyone have another suggestion? Thank you

like image 244
Randnum Avatar asked Sep 11 '25 07:09

Randnum


2 Answers

I've also added the MySQL driver .jars to the library of glassfish in both projects.

It was apparently not done right. The JAR has to go in /glassfish/domains/[domainname]/lib/ext folder of the Glassfish installation where [domainname] usually defaults to domain1. You can and should not configure it from the Eclipse side on.

like image 133
BalusC Avatar answered Sep 13 '25 02:09

BalusC


Looks like I am replying very late, but however people who would be referring to this thread may find the following information being useful. So I am posting it here:

  1. Download the connector Jar from http://dev.mysql.com/downloads/connector/j/5.0.html
  2. unzip the pack and copy mysql-connector-java-verno-bin.jar
  3. past the same at [GlassFish Installation Directory]/domains/[domain name]/lib folder
  4. restart your domain and ping to check your connection in JDBC Connection Pools

There you go. If your MySql is running then it will ping the DB successfully

like image 30
Ram Avatar answered Sep 13 '25 01:09

Ram