如何部署一个 webapp 并创建它的资源 [英] how to deploy a webapp and create its resources

查看:22
本文介绍了如何部署一个 webapp 并创建它的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 glassfish 4 上部署myapp.war"之前,我必须

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

  1. 创建 jdbc 连接池(/WEB-INF/glassfish-resources.xml -> jdbc-connection-pool 本身不起作用... asadmin 很好)
  2. 为池创建 jdbc 资源(/WEB-INF/glassfish-resources.xml -> jdbc-resource 同上)
  3. 创建 auth-realm(没有自动,现在使用 asadmin)
  4. 创建模式(peristence.xml -> property javax.persistence.schema-generation.create-database-schemas,但是是假的)
  5. 创建表(persistence.xml -> `create-tables',虽然不完美但至少可以工作)
  1. create jdbc connection pool (/WEB-INF/glassfish-resources.xml -> jdbc-connection-pool does not work by itself... fine from asadmin)
  2. create jdbc resource for pool (/WEB-INF/glassfish-resources.xml -> jdbc-resource same as above)
  3. create auth-realm (nothing auto, using asadmin for now)
  4. create schema (peristence.xml -> property javax.persistence.schema-generation.create-database-schemas, but is bogus)
  5. create tables (persistence.xml -> `create-tables', not perfect but at least it works)

现在我在做:

  1. 在/tmp/install 上上传myapp.war"、glassfish-resources.xml"
  2. asadmin add-resources ...
  3. asadmin create-auth-realm ...
  4. asadmin deploy ...
  5. asadmin 禁用 myapp ...
  6. nano/.../glassfish/applications/myapp/WEB-INF/classes/META-INF/persistence.xml
  7. 注释几行,ctrl+oenterctrl+xenter
  8. asadmin enable myapp ...
  9. rm -Rf/tmp/install

在没有其他建议的情况下,我打算:

and without other suggestion i'm planning to:

  1. 在/tmp/install 上上传myapp.war"、deploy.sh"
  2. chmod +x deploy.sh
  3. ./deploy.sh

脚本会处理一切.但我想通过 glassfish http 控制台上传一个战争文件并获得相同的结果.

and the script will take care of everything. but i'd like to upload only a war file via glassfish http console and obtain the same result.

有没有办法让一个名为before contextInitialized 的类或脚本?

is there a way to have a class or script called before contextInitialized?

你会如何部署这个东西?

how would you deploy this thing?

为了完整起见,这里有一些附加信息:

for completeness here are some additional info:

/myapp/WEB-INF/classes/META-INF/persistence.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="myapp" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/myapp</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <shared-cache-mode>NONE</shared-cache-mode>
        <properties>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/myapp"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="password"/>
            <property name="javax.persistence.schema-generation.database.action" value="create"/>
            <property name="javax.persistence.schema-generation.create-database-schemas" value="false"/>
            <property name="javax.persistence.schema-generation.scripts.action" value="drop-and-create"/>
            <property name="javax.persistence.schema-generation.scripts.create-target" value="C:/tmp/myapp_create.ddl"/>
            <property name="javax.persistence.schema-generation.scripts.drop-target" value="C:/tmp/myapp_drop.ddl"/>
            <property name="eclipselink.deploy-on-startup" value="true"/>
            <property name="eclipselink.target-database" value="MySQL"/>
<!--            <property name="eclipselink.ddl-generation" value="create-tables"/> -->
<!--            <property name="eclipselink.ddl-generation.output-mode" value="database"/> -->
<!--            <property name="eclipselink.create-ddl-jdbc-file-name" value="myapp.ddl"/> -->
<!--            <property name="eclipselink.logging.level" value="FINE" /> -->
<!--            <property name="eclipselink.logging.level.sql" value="FINE"/> -->
<!--            <property name="eclipselink.logging.parameters" value="true"/> -->
<!--            <property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSessionLog"/> -->
        </properties>
    </persistence-unit>
</persistence>

/myapp/WEB-INF/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-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="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" 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="jdbc/myapp_pool" 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="3306"/>
        <property name="databaseName" value="myapp"/>
        <property name="User" value="root"/>
        <property name="Password" value="password"/>
        <property name="URL" value="jdbc:mysql://localhost:3306/myapp"/>
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
    </jdbc-connection-pool>
    <jdbc-resource enabled="true" jndi-name="jdbc/myapp" object-type="user" pool-name="jdbc/myapp_pool"/>
</resources>

虽然 glassfish 理解/myapp/.../persistence.xml(有时也执行 CREATE SCHEMA myapp,有时不是,显然是随机的 - 但它很好),

while glassfish understands /myapp/.../persistence.xml (sometimes executing also CREATE SCHEMA myapp, sometimes not, apparently random - but it's fine),

我绝对不能让 glassfish 读取/myapp/WEB-INF/glassfish-resources.xml.它忽略这个文件.

i definitely can't make glassfish read /myapp/WEB-INF/glassfish-resources.xml. it ignores this file.

更新glassfish 读取文件,但在 jndi 名称前加上 java:app/ 会破坏其他引用.意识到这件事后,我用前缀重写了引用,现在它工作正常.最后,我注意到如果 glassfish-resources.xmlMETA-INF(而不是 WEB-INF)内, glassfish 会读取文件并且它也存在于 http ui 下的应用程序 > myapp > 描述符"

UPDATE glassfish reads the file but prefixes jndi names with java:app/ breaking other references. being aware of this thing i rewrite references with prefix and now it is working fine. lastly, i noted that if glassfish-resources.xml is inside META-INF (instead of WEB-INF) glassfish reads the file and it is also present in http ui under "applications > myapp > descriptors"

推荐答案

我终于找到了解决方案:

finally i found a solution:

  1. 数据库创建/升级:在ServletContextListener.contextInitialized中,如果不存在,我使用编译时生成的ddl脚本创建数据库,或者使用liquibase升级数据库如果存在.不再使用persistence.xml 来生成数据库.

  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.

身份验证领域部署:我不部署或创建任何特定于容器的领域.在 ServletContextListener.contextInitialized 中,我注册了一个自定义的 JASPIC 实现,它本身就是一个 JAAS 登录模块包装器.感谢@ArjanTijms 提供这篇文章这个答案

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

这篇关于如何部署一个 webapp 并创建它的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆