eclipse 未为 com.mysql.jdbc.jdbc2.optional.MysqlXADataSource 设置部署到 Glassfish 类路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10965926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Deploying to Glassfish classpath not set for com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
提问by Sara
Glassfish is not loading the com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
package.
Glassfish 未加载com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
包。
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.
我已经将mysql-connector jar 文件复制到lib
Glassfish的目录下,但仍然出现上述错误。
How do I ensure that Glassfish can find my JDBC driver for my deployed application?
如何确保 Glassfish 可以为我部署的应用程序找到我的 JDBC 驱动程序?
回答by Rob Kielty
You will need to make the MySQL JDBC jar file available to Glassfish.
您需要使 MySQL JDBC jar 文件可用于 Glassfish。
http://ushainformatique.com/blog/2010/03/19/jdbcwithglassfish/
http://ushainformatique.com/blog/2010/03/19/jdbcwithglassfish/
EDIT:
编辑:
How do I use different JDBC drivers? Where should I copy the jar(s)?
如何使用不同的 JDBC 驱动程序?我应该在哪里复制罐子?
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.
建议将域中所有应用程序使用的 JDBC 驱动程序放在 domain-dir/lib 或 domain-dir/lib/classes 中。今天需要重新启动应用程序服务器实例,以便 JDBC 驱动程序对部署在域中的应用程序可见。
From https://blogs.oracle.com/sivakumart/entry/classloaders_in_glassfish_an_attempt
来自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.
因此,将 jar 文件移动到要部署应用程序的域下的 lib 目录中。默认的 Glassfish 域是 domain1。
Restart Glassfish and this should work.
重新启动 Glassfish,这应该可以工作。
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.
有一个 Maven Glassfish 插件可能值得评估http://maven-glassfish-plugin.java.net/Using Maven,这个插件将有助于自动化部署步骤。这将比进行手动部署更健壮。当然,你的电话。
回答by BrainO2
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.
除了将驱动程序添加到类路径之外,您还应该尝试将 appserv-rt.jar 文件添加到项目的构建路径中(该 jar 位于 Glassfish 的 lib 目录中)。如果不想包含所有其他 jar,则应首先创建一个包含 appserv-rt jar 的库,然后将其添加到项目的构建路径中。
回答by user3085764
We could fix using ./asadmin start-database This starts Derby (don't know why this is required, may be a bug, and I dont use this DB in my app) :)
我们可以使用 ./asadmin start-database 修复这会启动 Derby(不知道为什么需要这样做,可能是一个错误,我不在我的应用程序中使用这个数据库):)