Maven 嵌入式 Glassfish 插件 - 数据源和 JDBC 驱动程序

发布于 2024-11-13 07:32:10 字数 2117 浏览 3 评论 0原文

我正在尝试遵循 这种 方法为嵌入式 glassfish 创建数据源。本教程和我的代码之间唯一显着的区别是我使用官方 Maven 插件和 embedded-glassfish:run 目标运行服务器。

pom 文件中存在 JDBC 驱动程序的依赖项:

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>1.3.155</version>
</dependency> 

而我的 glassfish-resources.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
  <jdbc-resource enabled="true" jndi-name="jdbc/myDatasource" object-type="user" pool-name="connectionPool">
    <description/>
  </jdbc-resource>
  <jdbc-connection-pool datasource-classname="org.h2.jdbcx.JdbcDataSource"  name="connectionPool" res-type="javax.sql.DataSource">
    <property name="URL" value="jdbc:h2:~/Documents/Projetos/DBs/h2/glassfish/glassfish;AUTO_SERVER=TRUE;MVCC=TRUE"/>
    <property name="User" value="sa"/>
    <property name="Password" value=""/>
    <property name="driverClass" value="org.h2.Driver"/>
  </jdbc-connection-pool>
</resources> 

它使用本地 glassfish 服务器运行良好。但嵌入式实例并不幸运:

2011年3月6日 19:26:31 com.sun.enterprise.v3.server.ApplicationLifecycle 部署 GRAVE:无效资源: jdbc/myDatasource_pm java.lang.RuntimeException:无效 资源:jdbc/myDatasource_pm at com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:539) 在 com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:468) 在 org.glassfish.persistence.common.PersistenceHelper.lookupPMResource(PersistenceHelper.java:63) 在 org.glassfish.persistence.jpa.ProviderContainerContractInfoBase.lookupDataSource(ProviderContainerContractInfoBase.java:71) 在

...有人能解释一下吗?

I'm trying to follow this approach to create a datasource for embedded glassfish. The only significant difference between the tutorial and my code is that I'm running the server using the official maven plugin and the embedded-glassfish:run goal.

There is a dependency for the JDBC driver in the pom file:

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>1.3.155</version>
</dependency> 

And my glassfish-resources.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
  <jdbc-resource enabled="true" jndi-name="jdbc/myDatasource" object-type="user" pool-name="connectionPool">
    <description/>
  </jdbc-resource>
  <jdbc-connection-pool datasource-classname="org.h2.jdbcx.JdbcDataSource"  name="connectionPool" res-type="javax.sql.DataSource">
    <property name="URL" value="jdbc:h2:~/Documents/Projetos/DBs/h2/glassfish/glassfish;AUTO_SERVER=TRUE;MVCC=TRUE"/>
    <property name="User" value="sa"/>
    <property name="Password" value=""/>
    <property name="driverClass" value="org.h2.Driver"/>
  </jdbc-connection-pool>
</resources> 

It runs fine using a local glassfish server. But no lucky with the embedded instance:

03/06/2011 19:26:31
com.sun.enterprise.v3.server.ApplicationLifecycle
deploy GRAVE: Invalid resource :
jdbc/myDatasource_pm
java.lang.RuntimeException: Invalid
resource : jdbc/myDatasource
_pm at
com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:539)
at
com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:468)
at
org.glassfish.persistence.common.PersistenceHelper.lookupPMResource(PersistenceHelper.java:63)
at
org.glassfish.persistence.jpa.ProviderContainerContractInfoBase.lookupDataSource(ProviderContainerContractInfoBase.java:71)
at

I'm clueless... Can anyone shed some light on it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

櫻之舞 2024-11-20 07:32:10

想通了。毕竟它与 glassfish-resources.xml 无关。 jdbc 资源已正确创建并绑定到 java:app/jdbc/myDatasource

我的持久性单元(由 Netbeans 生成)正在寻找 jdbc/myDatasource 但没有找到任何内容。
我最终更改了我的持久性单元以指向应用程序名称空间:

<jta-data-source>java:app/jdbc/myDatasource</jta-data-source>

另一个选择是使用 embedded-glassfish:admin 目标来部署具有非标准名称的全局资源(以便我可以使用 <代码>jdbc/myDatasource)。但采用标准似乎是最好的方法。

这个主题非常有帮助。

Figured it out. It had nothing to do with glassfish-resources.xml after all. The jdbc resource was properly created and bound to java:app/jdbc/myDatasource.

My persistence unit (generated by Netbeans) was looking for jdbc/myDatasource and not finding anything.
I ended up changing my persistence unit to point to the application namespace:

<jta-data-source>java:app/jdbc/myDatasource</jta-data-source>

Another option would be using the embedded-glassfish:admin goal to deploy a global resource with non-standard name (so that I could use jdbc/myDatasource). But going standard seemed like the best approach.

This topic was very helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文