Java – how to deploy webapp and create its resources

I had to do this before deploying "myapp. War" on GlassFish 4

>Create JDBC connection pool (/ WEB-INF / glassfish-resources.xml – > JDBC connection pool itself does not work... It can work normally from asadmin) > create JDBC resources for the pool (/ WEB-INF / glassfish-resources.xml – > JDBC resource is the same as above) > create auth realm (not automatic, now use asadmin) > create schema (persistence.xml – > attribute javax.persistence.schema-generation.create-database-schemas, but forged) > create tables (persistence.xml – > ` create tables', not perfect, but at least it works)

Now I'm doing:

>Upload "myapp. War", "GlassFish resources. XML" > asadmin add resources... > asadmin create auth realm... > asadmin deployment... > asadmin disable myapp... > nano /... / GlassFish / applications / myapp / WEB-INF / classes / meta inf / persistence XML > comment lines, Ctrl o, enter, Ctrl x, enter > asadmin enable myapp... > RM - RF / TMP / install

Without further suggestions, I intend to:

>Upload "myapp. War", "deploy. Sh" > Chmod x deploy. Sh "in / TMP / install sh > ./ deploy. sh

And the script will handle everything But I want to upload a war file through GlassFish HTTP console and get the same result

Is there any way to call a class or script before contextInitialized?

How would you deploy this?

For completeness, here are some additional information:

/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>

Although GlassFish knows / myapp /... / persistence XML (sometimes create schema myapp is executed, sometimes not, obviously random - but it's good),

I can never read GlassFish as / myapp / WEB-INF / GlassFish resources xml. It ignores this file

Update GlassFish reads the file, but uses Java: APP / destroys the JNDI name prefix of other references Knowing this, I rewrite the reference with prefix, and now it works normally Finally, I noticed that if GlassFish resources If XML is in meta-inf (not WEB-INF), GlassFish will read the file, and it also exists in HTTP UI under http: "Applications > myapp > descriptors"

Solution

Finally, I found a solution:

>Database creation / upgrade: in servletcontextlistener In contextinitialized, I use the DDL script generated at compile time to create the database (if it does not exist), or use liquibase to upgrade the database (if it exists) There is no longer a persistence. For database generation XML usage. > Authentication realm deployment: I do not deploy or create any container - specific realm In servletcontextlistener In contextinitialized, I registered a custom jaspic implementation, which itself is a JAAS login module wrapper Thank @ arjantijms for this Oracle and this answer

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>