how to deploy a webapp and create its resources

前端 未结 2 538
清酒与你
清酒与你 2020-12-15 01:29

before deploy \"myapp.war\" on glassfish 4 i have to

  1. create jdbc connection pool (/WEB-INF/glassfish-resources.xml -> jdbc-connection-pool does no
相关标签:
2条回答
  • 2020-12-15 01:58

    finally i found a solution:

    1. database create/upgrade: in ServletContextListener.contextInitialized i use compile-time-generated ddl script to create database if not exists, or use liquibase to upgrade database if exists. no more persistence.xml usage for database generation.

    2. authentication realm deploy: i don't deploy or create any container-specific realm. in ServletContextListener.contextInitialized i register a custom JASPIC implementation, which is itself a JAAS login module wrapper. thanks to @ArjanTijms for this aricle and this answer

    0 讨论(0)
  • 2020-12-15 02:15

    You can configure application scoped resources for the jdbc-connection-pool and jdbc-resource inside the glassfish-resources.xml and when you deploy your WAR file they will be created. When you undeploy your WAR they will go away. That solves the problem of manually adding them with asadmin. What I usually do it set it up manually using the GUI, then copy and paste the <jdbc-connection-pool> and <jdbc-resource> elements from the domain.xml into glassfish-resources.xml then I change the jndi-name to be application scoped, for example:

    <jdbc-resource pool-name="MyAppPool" jndi-name="java:app/jdbc/my-app-pool"></jdbc-resource>
    

    Then I make sure glassfish-resources.xml is packaged into the appropriate place in the WAR file, namely in the WEB-INF folder.

    From what I have read in the Oracle documentation for Glassfish 4 it does not appear that you can package the auth-realm configuration with the application like you can for the JDBC stuff. I have filed an enhancement request for this glassfish auth-realm packaging enhancement It only appears that you can package the association to the realm in various deployment descriptors, see the "How to set a realm for an Application or Module" section of this guide for details.

    HACK Alert

    Actually I just thought of something which is a bit of a hack but might work around this issue. You could create a simple web APP which includes your real applications WAR file in it (in a resource directory). This wrapper app would include a REST client (like Jersey client) which would make REST calls to the Glassfish administration REST API to see if the auth-realm is there and configured. If it is it would use the REST API to deploy the embedded WAR file. If it isn't it would use the REST API to create the auth-realm and then it would deploy the WAR.

    I'm not quite clear on the issues you are having with schema generation but that's all supported via the persistence.xml and works fine. If you want even more functionality in the way of automatic migration scripting then I would look at integrating a package like FlyAway

    Here's an example of a glassfish-resources.xml file with app scoped resources which works for me under Glassfish 3.1.2. Some of the attributes you have I don't and I also don't use a JDBC JNDI naming style for the pool-name on the jdbc-resource.

    <?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-connection-pool validation-table-name="TABLEVALIDATION" allow-non-component-callers="true"
                              statement-cache-size="200" associate-with-thread="true" statement-timeout-in-seconds="300"
                              non-transactional-connections="true" connection-leak-reclaim="true"
                              lazy-connection-association="true" connection-creation-retry-attempts="12"
                              lazy-connection-enlistment="true" validate-atmost-once-period-in-seconds="120"
                              statement-leak-timeout-in-seconds="360"
                              datasource-classname="oracle.jdbc.pool.OracleDataSource" res-type="javax.sql.DataSource"
                              connection-leak-timeout-in-seconds="420" statement-leak-reclaim="true"
                              name="UnitTestPool" is-connection-validation-required="true">
            <property name="DataSourceName" value="OracleDataSource"></property>
            <property name="ImplicitCachingEnabled" value="false"></property>
            <property name="NetworkProtocol" value="tcp"></property>
            <property name="DatabaseName" value="unittestdb"></property>
            <property name="LoginTimeout" value="0"></property>
            <property name="Password" value="tester"></property>
            <property name="URL" value="jdbc:oracle:thin:@testbed:1521:xe"></property>
            <property name="User" value="testertester"></property>
            <property name="PortNumber" value="1521"></property>
            <property name="ExplicitCachingEnabled" value="false"></property>
            <property name="dynamic-reconfiguration-wait-timeout-in-seconds" value="960"></property>
            <property name="MaxStatements" value="0"></property>
        </jdbc-connection-pool>
        <jdbc-resource pool-name="UnitTestPool" jndi-name="java:app/jdbc/unittestdb-pool"></jdbc-resource>
    </resources>
    
    0 讨论(0)
提交回复
热议问题