我想分享在企业应用程序开发中使用payara-micro的经验。 我希望有人可以节省时间,因为这样的决定没有立即做出。 如果您已经将Payara或Glassfish用作工业服务器,或者只是打算涉足Javaee领域,那么请使用payara-micro,这是您的最佳选择。
您将需要一个通过maven组装到war归档中的Web应用程序和Java 8(我没有检查较旧的应用程序)。
首先,我将提供概要文件的全文,然后将其解析为小段并添加在源代码中不可见的缺少的细节。
Payara-micro的Maven个人资料<profile> <id>micro</id> <build> <plugins> <plugin> <artifactId>maven-dependency-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>copy-payara-micro</id> <phase>package</phase> <goals> <goal>copy</goal> </goals> <configuration> <outputDirectory>${project.build.directory}</outputDirectory> <stripVersion>true</stripVersion> <silent>true</silent> <artifactItems> <artifactItem> <groupId>fish.payara.extras</groupId> <artifactId>payara-micro</artifactId> <type>jar</type> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin> <cut/> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <goals> <goal>exec</goal> </goals> </execution> </executions> <configuration> <executable>java</executable> <arguments> <argument>-XXaltjvm=dcevm</argument> <argument>-javaagent:hotswap/hotswap-agent.jar</argument> <argument>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9009</argument> <argument>-Duser.language=en</argument> <argument>-Duser.region=US</argument> <argument>-Ddb.ora.url=jdbc:p6spy:oracle:thin:@localhost:1521:XE</argument> <argument>-Ddb.pg.url=jdbc:p6spy:postgresql://localhost:5432/postgres</argument> <argument>-jar</argument> <argument>${project.build.directory}/${project.build.finalName}-microbundle.jar</argument> <argument>--domainConfig</argument> <argument>src/main/setup/domain.xml</argument> <argument>--deploy</argument> <argument>${project.build.directory}/${project.build.finalName}.war</argument> <argument>--rootDir</argument> <argument>${project.build.directory}/payaramicro</argument> </arguments> </configuration> </plugin> <plugin> <groupId>fish.payara.maven.plugins</groupId> <artifactId>payara-micro-maven-plugin</artifactId> <version>1.0.0</version> <executions> <execution> <goals> <goal>bundle</goal> <goal>start</goal> </goals> </execution> </executions> <configuration> <payaraVersion>4.1.2.173</payaraVersion> <autoDeployArtifact>false</autoDeployArtifact> <customJars> <artifactItem> <groupId>p6spy</groupId> <artifactId>p6spy</artifactId> <version>2.3.1</version> </artifactItem> <artifactItem> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.3</version> </artifactItem> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>42.2.0</version> </dependency> </customJars> </configuration> </plugin> </plugins> </build> <cut/> <dependencies> <dependency> <groupId>fish.payara.extras</groupId> <artifactId>payara-micro</artifactId> <version>4.1.2.173</version> <scope>provided</scope> </dependency> <dependency> <groupId>p6spy</groupId> <artifactId>p6spy</artifactId> <version>2.3.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.3</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>42.2.0</version> <scope>provided</scope> </dependency> </dependencies> </profile>
首先要做的是下载payara-micro存档本身。 这正是第一个插件( maven-dependency-plugin )所做的。 归档文件是一个完整的应用程序服务器,可以从命令行作为简单的Java应用程序启动。
最新的插件( payara-micro-maven-plugin )没有功能,并且已配置为payra-micro 4.1.2.173的稳定工作版本。 在插件的功能中,此处使用了将Web应用程序打包到准备运行的特殊捆绑软件中的功能。 还有其他启动Payara-micro的方法,但在这里它们对我们没有用。
仍然需要生成所需的命令行并将所有内容放在一起。 exec-maven-plugin用于从命令行启动。 让我们仔细看看命令行参数:
<configuration> <executable>java</executable> <arguments> <argument>-XXaltjvm=dcevm</argument> <argument>-javaagent:hotswap/hotswap-agent.jar</argument> <argument>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9009</argument> <argument>-Duser.language=en</argument> <argument>-Duser.region=US</argument> <argument>-Ddb.ora.url=jdbc:p6spy:oracle:thin:@localhost:1521:XE</argument> <argument>-Ddb.pg.url=jdbc:p6spy:postgresql://localhost:5432/postgres</argument> <argument>-jar</argument> <argument>${project.build.directory}/${project.build.finalName}-microbundle.jar</argument> <argument>--domainConfig</argument> <argument>src/main/setup/domain.xml</argument> <argument>--deploy</argument> <argument>${project.build.directory}/${project.build.finalName}.war</argument> <argument>--rootDir</argument> <argument>${project.build.directory}/payaramicro</argument> </arguments> </configuration>
需要前两个参数( -XXaltjvm = dcevm -javaagent:hotswap / hotswap-agent.jar )来更改源代码而无需重新启动应用程序。 由于有了第二个参数( -agentlib:jdwp = transport = dt_socket,server = y,suspend = n,address = 9009 ),我们立即以调试模式启动应用程序,这使我们不仅可以通过在IDE的调试中应用代码更改的方式来更改方法本身。 ,还可以添加新字段等。 您只需要从IDE与调试器连接,编译修改后的源文件并应用更改。
要使 jdbc客户端与Oracle正确配合使用,需要以下两个参数( -Duser.language = zh -Duser.region = US )。 连接到测试DBMS的设置通过-D参数传递。 在我的应用程序中,我使用了类似于$ {db.ora.url}的链接到资源文件中的这些参数,该参数在启动时自动创建。 还可以通过maven中的配置文件及其过滤文本文件的功能来实现用测试或工业设置创建资源的文件替换。
启动时的关键参数指示域设置文件的路径( --domainConfig src / main / setup / domain.xml ),以及war文件的路径( --deploy $ {project.build.directory} / $ {project。 build.finalName} .war )部署到服务器。 域设置是我根据档案内部的标准文件获得的。 我将以内容为例。 对于在这些设置的开发中使用是绰绰有余的。
domain.xml <domain log-root="${com.sun.aas.instanceRoot}/logs" application-root="${com.sun.aas.instanceRoot}/applications" version="10.0"> <security-configurations> <authorization-service default="true" name="authorizationService"> <security-provider name="simpleAuthorization" type="Simple" provider-name="simpleAuthorizationProvider"> <authorization-provider-config support-policy-deploy="false" name="simpleAuthorizationProviderConfig"></authorization-provider-config> </security-provider> </authorization-service> </security-configurations> <system-applications /> <applications /> <resources> <jdbc-resource pool-name="DerbyPool" jndi-name="jdbc/__default" object-type="system-all" /> <jdbc-connection-pool is-isolation-level-guaranteed="false" name="DerbyPool" datasource-classname="org.apache.derby.jdbc.EmbeddedDataSource" res-type="javax.sql.DataSource"> <property name="databaseName" value="${com.sun.aas.instanceRoot}/lib/databases/embedded_default" /> <property name="connectionAttributes" value=";create=true" /> </jdbc-connection-pool> <context-service description="context service" jndi-name="concurrent/__defaultContextService" object-type="system-all"></context-service> <managed-executor-service maximum-pool-size="200" core-pool-size="6" long-running-tasks="true" keep-alive-seconds="300" hung-after-seconds="300" task-queue-capacity="20000" jndi-name="concurrent/__defaultManagedExecutorService" object-type="system-all"></managed-executor-service> <managed-scheduled-executor-service core-pool-size="6" long-running-tasks="true" keep-alive-seconds="300" hung-after-seconds="300" jndi-name="concurrent/__defaultManagedScheduledExecutorService" object-type="system-all"></managed-scheduled-executor-service> <managed-thread-factory description="thread factory" jndi-name="concurrent/__defaultManagedThreadFactory" object-type="system-all"></managed-thread-factory> </resources> <servers> <server name="server" config-ref="server-config"> <resource-ref ref="jdbc/__default" /> </server> </servers> <configs> <config name="server-config"> <health-check-service-configuration enabled="false"> <log-notifier enabled="true"/> <eventbus-notifier enabled="false"/> <cpu-usage-checker unit="MINUTES" name="CPU" time="1" enabled="true" /> <machine-memory-usage-checker unit="MINUTES" name="MMEM" time="3" enabled="true" /> <heap-memory-usage-checker unit="MINUTES" name="HEAP" time="3" enabled="true" /> <hogging-threads-checker unit="MINUTES" name="HT" time="5" enabled="true" /> <garbage-collector-checker unit="MINUTES" name="GC" time="5" enabled="true" /> </health-check-service-configuration> <http-service access-logging-enabled="false"> <access-log format="%client.name% %auth-user-name% %datetime% %request% %status% %response.length%" rotation-interval-in-minutes="15" rotation-suffix="yyyy-MM-dd"></access-log> <virtual-server id="server" access-logging-enabled="false" access-log="" network-listeners="http-listener, https-listener"></virtual-server> </http-service> <iiop-service> <orb use-thread-pool-ids="thread-pool-1"></orb> <iiop-listener id="orb-listener-1" enabled="false" address="0.0.0.0"></iiop-listener> </iiop-service> <admin-service system-jmx-connector-name="system" type="das-and-server"> <jmx-connector port="8686" address="0.0.0.0" security-enabled="false" auth-realm-name="admin-realm" name="system" enabled="false"></jmx-connector> <das-config></das-config> </admin-service> <connector-service class-loading-policy="global" shutdown-timeout-in-seconds="30"> </connector-service> <log-service file="${com.sun.aas.instanceRoot}/logs/server.log" log-rotation-limit-in-bytes="2000000"> <module-log-levels /> </log-service> <security-service activate-default-principal-to-role-mapping="true" jacc="simple"> <auth-realm classname="com.sun.enterprise.security.auth.realm.file.FileRealm" name="admin-realm"> <property value="${com.sun.aas.instanceRoot}/config/admin-keyfile" name="file" /> <property value="fileRealm" name="jaas-context" /> </auth-realm> <auth-realm classname="com.sun.enterprise.security.auth.realm.file.FileRealm" name="file"> <property value="${com.sun.aas.instanceRoot}/config/keyfile" name="file" /> <property value="fileRealm" name="jaas-context" /> </auth-realm> <auth-realm classname="com.sun.enterprise.security.auth.realm.certificate.CertificateRealm" name="certificate" /> <jacc-provider policy-configuration-factory-provider="com.sun.enterprise.security.provider.PolicyConfigurationFactoryImpl" policy-provider="com.sun.enterprise.security.provider.PolicyWrapper" name="default"> <property value="${com.sun.aas.instanceRoot}/generated/policy" name="repository" /> </jacc-provider> <jacc-provider policy-configuration-factory-provider="com.sun.enterprise.security.jacc.provider.SimplePolicyConfigurationFactory" policy-provider="com.sun.enterprise.security.jacc.provider.SimplePolicyProvider" name="simple" /> <audit-module classname="com.sun.enterprise.security.ee.Audit" name="default"> <property value="false" name="auditOn" /> </audit-module> <message-security-config auth-layer="SOAP"> <provider-config provider-id="XWS_ClientProvider" class-name="com.sun.xml.wss.provider.ClientSecurityAuthModule" provider-type="client"> <request-policy auth-source="content" /> <response-policy auth-source="content" /> <property value="s1as" name="encryption.key.alias" /> <property value="s1as" name="signature.key.alias" /> <property value="false" name="dynamic.username.password" /> <property value="false" name="debug" /> </provider-config> <provider-config provider-id="ClientProvider" class-name="com.sun.xml.wss.provider.ClientSecurityAuthModule" provider-type="client"> <request-policy auth-source="content" /> <response-policy auth-source="content" /> <property value="s1as" name="encryption.key.alias" /> <property value="s1as" name="signature.key.alias" /> <property value="false" name="dynamic.username.password" /> <property value="false" name="debug" /> <property value="${com.sun.aas.instanceRoot}/config/wss-server-config-1.0.xml" name="security.config" /> </provider-config> <provider-config provider-id="XWS_ServerProvider" class-name="com.sun.xml.wss.provider.ServerSecurityAuthModule" provider-type="server"> <request-policy auth-source="content" /> <response-policy auth-source="content" /> <property value="s1as" name="encryption.key.alias" /> <property value="s1as" name="signature.key.alias" /> <property value="false" name="debug" /> </provider-config> <provider-config provider-id="ServerProvider" class-name="com.sun.xml.wss.provider.ServerSecurityAuthModule" provider-type="server"> <request-policy auth-source="content" /> <response-policy auth-source="content" /> <property value="s1as" name="encryption.key.alias" /> <property value="s1as" name="signature.key.alias" /> <property value="false" name="debug" /> <property value="${com.sun.aas.instanceRoot}/config/wss-server-config-1.0.xml" name="security.config" /> </provider-config> </message-security-config> <property value="SHA-256" name="default-digest-algorithm" /> </security-service> <transaction-service tx-log-dir="${com.sun.aas.instanceRoot}/logs" > </transaction-service> <hazelcast-runtime-configuration enabled="false" multicastGroup="224.2.2.4" multicastPort="2904" generate-names="true"></hazelcast-runtime-configuration> <phone-home-runtime-configuration></phone-home-runtime-configuration> <request-tracing-service-configuration> <log-notifier enabled="true"></log-notifier> </request-tracing-service-configuration> <notification-service-configuration enabled="true"> <log-notifier-configuration enabled="true"></log-notifier-configuration> <eventbus-notifier-configuration enabled="false"></eventbus-notifier-configuration> </notification-service-configuration> <batch-runtime-configuration table-prefix="jbatch" data-source-lookup-name="jdbc/__default"></batch-runtime-configuration> <availability-service availability-enabled="true" > <web-container-availability availability-enabled="true" persistence-scope="modified-session" sso-failover-enabled="true" persistence-type="hazelcast"></web-container-availability> </availability-service> <network-config> <protocols> <protocol name="http-listener"> <http default-virtual-server="server" xpowered-by="false" max-connections="250" comet-support-enabled="true"> <file-cache enabled="false"></file-cache> </http> </protocol> <protocol security-enabled="true" name="https-listener"> <http default-virtual-server="server" xpowered-by="false" comet-support-enabled="true" max-connections="250"> <file-cache enabled="false"></file-cache> </http> <ssl classname="com.sun.enterprise.security.ssl.GlassfishSSLImpl" ssl3-enabled="false" cert-nickname="s1as"></ssl> </protocol> </protocols> <network-listeners> <network-listener port="8080" protocol="http-listener" transport="tcp" name="http-listener" thread-pool="http-thread-pool" enabled="true" /> <network-listener port="8443" protocol="https-listener" transport="tcp" name="https-listener" thread-pool="http-thread-pool" enabled="false" /> </network-listeners> <transports> <transport byte-buffer-type="HEAP" name="tcp" acceptor-threads="-1"></transport> </transports> </network-config> <thread-pools> <thread-pool name="http-thread-pool" min-thread-pool-size="10" max-thread-pool-size="200" max-queue-size="4096"></thread-pool> <thread-pool name="thread-pool-1" min-thread-pool-size="2" max-thread-pool-size="200"/> </thread-pools> </config> </configs> <system-property name="fish.payara.classloading.delegate" value="false"/> <property name="administrative.domain.name" value="domain1"/> </domain>
我还将提供一个资源描述文件的示例,该文件可在应用程序启动时自动创建它们。
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="java:app/ora_con" object-type="user" pool-name="java:app/OraPool"/> <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="table" driver-classname="com.p6spy.engine.spy.P6SpyDriver" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="true" 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="java:app/OraPool" non-transactional-connections="false" ping="false" pool-resize-quantity="2" pooling="true" res-type="java.sql.Driver" statement-cache-size="0" statement-leak-reclaim="false" statement-leak-timeout-in-seconds="0" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" validation-table-name="DUAL" wrap-jdbc-objects="true"> <property name="URL" value="${db.ora.url}"/> <property name="User" value="system"/> <property name="Password" value="1"/> <property name="property.dynamic-reconfiguration-waittimeout-in-seconds" value="60" /> </jdbc-connection-pool> <jdbc-resource enabled="true" jndi-name="java:app/pg_con" object-type="user" pool-name="java:app/PGPool"/> <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="table" driver-classname="com.p6spy.engine.spy.P6SpyDriver" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="true" 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="java:app/PGPool" non-transactional-connections="false" ping="false" pool-resize-quantity="2" pooling="true" res-type="java.sql.Driver" statement-cache-size="0" statement-leak-reclaim="false" statement-leak-timeout-in-seconds="0" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" validation-table-name="DUAL" wrap-jdbc-objects="true"> <property name="URL" value="${db.pg.url}"/> <property name="User" value="postgres"/> <property name="Password" value="postgres"/> <property name="property.dynamic-reconfiguration-waittimeout-in-seconds" value="60" /> </jdbc-connection-pool> </resources>
您可以从此处安装dcevm。 确保将其安装为替代JVM,以便您始终有机会使用常规默认值。
您可以从此处下载最新版本的代理,以进行无限制的源代码修改,以及在诸如hibernate之类的框架内重新加载代码。
为payara设置代码重载的想法来自这里 。 但事实仅是想法本身,因为在此不考虑使用payara-micro。
多亏了p6spy库,您可以在项目根文件夹-spy.log文件中找到sql日志。 可以根据需要自定义p6spy库,但这是另一篇文章的主题。
将上述配置文件放置在pom.xml中并将以上讨论的其他文件放置在适当的文件夹中之后,可以使用以下命令启动应用程序:
mvn install exec:exec -P micro
而且不需要在IDE中为应用程序服务器提供其他插件...