0

我使用 Netbeans 和 GlassFish 开发了 JPA 的 JSF 应用程序。它在 Netbeans 环境中运行良好。现在我想将其部署为具有不同数据库设置的远程 GlassFish 服务器。有什么方法可以在第一次部署到服务器时给出数据库设置并保存设置后记?我有一个 persistence.xml 文件,但数据库设置在 glassfish-resources.xml 文件中。

持久性.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
 <persistence-unit name="HOPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>dsHiLap2</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
    </properties>
 </persistence-unit>

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/ho" object-type="user" pool-name="connectionPoolHo">
        <description/>
    </jdbc-resource>
    <jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.apache.derby.jdbc.ClientDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="connectionPoolHo" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
        <property name="URL" value="jdbc:derby://localhost:1527/healthofice"/>
        <property name="serverName" value="localhost"/>
        <property name="PortNumber" value="1527"/>
        <property name="DatabaseName" value="healthofice"/>
        <property name="User" value="healthoffice"/>
        <property name="Password" value="health"/>
    </jdbc-connection-pool>
    <jdbc-resource enabled="true" jndi-name="dsDec2012" object-type="user" pool-name="connectionPoolHo"/>
    <jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.apache.derby.jdbc.ClientDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="derby_net_ho_hoPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
        <property name="serverName" value="localhost"/>
        <property name="portNumber" value="1527"/>
        <property name="databaseName" value="ho"/>
        <property name="User" value="ho"/>
        <property name="Password" value="ho"/>
        <property name="URL" value="jdbc:derby://localhost:1527/ho"/>
        <property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"/>
        </jdbc-connection-pool>
    <jdbc-resource enabled="true" jndi-name="dsHo" object-type="user" pool-name="derby_net_ho_hoPool"/>
    <jdbc-resource enabled="true" jndi-name="ds2013Feb" object-type="user" pool-name="connectionPoolHo"/>
    <jdbc-resource enabled="true" jndi-name="drHoBuddhikaDesktop1" object-type="user" pool-name="derby_net_ho_hoPool"/>
    <jdbc-resource enabled="true" jndi-name="drHoBuddhikaLaptop1" object-type="user" pool-name="connectionPoolHo"/>
    <jdbc-resource enabled="true" jndi-name="dsHiLap" object-type="user" pool-name="derby_net_ho_hoPool"/>
    <jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.apache.derby.jdbc.ClientDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="derby_net_ho1_ho1Pool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
        <property name="serverName" value="localhost"/>
        <property name="portNumber" value="1527"/>
        <property name="databaseName" value="ho1"/>
        <property name="User" value="ho1"/>
        <property name="Password" value="ho1"/>
        <property name="URL" value="jdbc:derby://localhost:1527/ho1"/>
        <property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"/>
</jdbc-connection-pool>
    <jdbc-resource enabled="true" jndi-name="dsHiLap2" object-type="user" pool-name="derby_net_ho1_ho1Pool"/>
</resources>
4

1 回答 1

2

您需要使用 GlassFish 部署计划为远程 GlassFish 服务器配置不同的连接池设置,因为 glassfish-resources.xml 定义了应用程序范围的资源。应用程序范围的连接池仅在应用程序部署期间创建。请参阅使用部署计划部署应用程序或模块。基本上,您在 deploymentplan.jar 中提供 glassfish-resources.xml 的远程服务器版本(遵循 module-name.gf-dd-name 命名约定)。

另一种选择是不使用应用程序范围的资源。您可以通过 GlassFish 管理控制台定义连接池/数据源。

于 2013-03-02T06:19:16.727 回答