Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying to Glassfish classpath not set for com.mysql.jdbc.jdbc2.optional.MysqlXADataSource

Glassfish is not loading the com.mysql.jdbc.jdbc2.optional.MysqlXADataSource package.

The following error is thrown

javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence
Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: 
Error in allocating a connection. Cause: Class name is wrong or classpath is not set    
for:com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
Error Code: 0 at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy
(EntityManagerSetupImpl.java:517)...

I have copied the mysql-connector jar file to the lib directory of Glassfish but I still get the above error.

How do I ensure that Glassfish can find my JDBC driver for my deployed application?

like image 876
Sara Avatar asked Jun 10 '12 02:06

Sara


2 Answers

You will need to make the MySQL JDBC jar file available to Glassfish.

http://ushainformatique.com/blog/2010/03/19/jdbcwithglassfish/

EDIT:

How do I use different JDBC drivers? Where should I copy the jar(s)?

It is recommended to place JDBC drivers, that are used by all the applications in the domain, in domain-dir/lib or domain-dir/lib/classes. A restart of the application server instance is required today so that the JDBC drivers are visible to applications deployed in the domain.

From https://blogs.oracle.com/sivakumart/entry/classloaders_in_glassfish_an_attempt

So move the jar file into the lib dir below the domain into which you are deploying your app. The default Glassfish domain is domain1.

Restart Glassfish and this should work.

There is a Maven Glassfish plugin which may be worth evaluating http://maven-glassfish-plugin.java.net/ Using Maven and this plugin would help automate the deployment step. This would be more robust than doing manual deployments. Your call though of course.

like image 96
Rob Kielty Avatar answered Sep 28 '22 02:09

Rob Kielty


Besides adding the driver to your classpath, you should try adding the appserv-rt.jar file to your project's build path (the jar is located in Glassfish's lib directory). If you don't want to include all the other jars you should first create a library containing the appserv-rt jar and then add it to your project's build path.

like image 43
BrainO2 Avatar answered Sep 28 '22 03:09

BrainO2