目前使用wildfly10作为应用容器进行ejb开发。每次修改-编译-部署耗时过长。使用jrebel之后可以实现热部署。下面是配置步骤:
1.下载jrebel
下载地址:http://zeroturnaround.com/software/jrebel/
2.配置maven插件
<?xml version="1.0" encoding="UTF-8"?> <!-- JBoss, Home of Professional Open Source Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual contributors by the @authors tag. See the copyright.txt in the distribution for a full listing of individual contributors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <name>wildfly-ejb3</name> <modelVersion>4.0.0</modelVersion> <groupId>org.wildfly.ejb3</groupId> <artifactId>wildfly-ejb3</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <url>http://wildfly.org</url> <licenses> <license> <name>Apache License, Version 2.0</name> <distribution>repo</distribution> <url>http://www.apache.org/licenses/LICENSE-2.0.html</url> </license> </licenses> <modules> <module>wildfly-ejb3-ejb</module> <module>wildfly-ejb3-web</module> <module>wildfly-ejb3-ear</module> </modules> <properties> <!-- Explicitly declaring the source encoding eliminates the following message: --> <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! --> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- JBoss dependency versions --> <version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin> <!-- Define the version of the JBoss BOMs we want to import to specify tested stacks. --> <version.jboss.bom>8.2.1.Final</version.jboss.bom> <version.wildfly>10.1.0.Final</version.wildfly> <!-- other plugin versions --> <version.compiler.plugin>3.1</version.compiler.plugin> <version.ear.plugin>2.10</version.ear.plugin> <version.ejb.plugin>2.3</version.ejb.plugin> <version.surefire.plugin>2.16</version.surefire.plugin> <version.war.plugin>2.5</version.war.plugin> <!-- maven-compiler-plugin --> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> </properties> <dependencyManagement> <dependencies> <!-- Define the version of the EJB jar so that we don't need to repeat ourselves in every module --> <dependency> <groupId>org.wildfly.ejb3</groupId> <artifactId>wildfly-ejb3-ejb</artifactId> <version>${project.version}</version> <type>ejb</type> </dependency> <!-- Define the version of the WAR so that we don't need to repeat ourselves in every module --> <dependency> <groupId>org.wildfly.ejb3</groupId> <artifactId>wildfly-ejb3-web</artifactId> <version>${project.version}</version> <type>war</type> <scope>compile</scope> </dependency> <!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection) of artifacts. We use this here so that we always get the correct versions of artifacts. Here we use the jboss-javaee-7.0-with-tools stack (you can read this as the JBoss stack of the Java EE 7 APIs, with some extras tools for your project, such as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate stack you can read this as the JBoss stack of the Java EE 7 APIs, with extras from the Hibernate family of projects) --> <dependency> <groupId>org.wildfly.bom</groupId> <artifactId>jboss-javaee-7.0-with-tools</artifactId> <version>${version.jboss.bom}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.wildfly.bom</groupId> <artifactId>jboss-javaee-7.0-with-hibernate</artifactId> <version>${version.jboss.bom}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <pluginManagement> <plugins> <!-- The WildFly plugin deploys your ear to a local JBoss AS container --> <!-- Due to Maven's lack of intelligence with EARs we need to configure the wildfly maven plugin to skip deployment for all modules. We then enable it specifically in the ear module. --> <plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>${version.wildfly.maven.plugin}</version> <inherited>true</inherited> <configuration> <skip>true</skip> </configuration> </plugin> <plugin> <groupId>org.zeroturnaround</groupId> <artifactId>jrebel-maven-plugin</artifactId> <version>1.1.6</version> <executions> <execution> <id>generate-rebel-xml</id> <phase>process-resources</phase> <goals> <goal>generate</goal> </goals> </execution> </executions> </plugin> </plugins> </pluginManagement> </build> </project>
3.配置应用启动脚本
在%JBOSS_HOME%\bin文件夹下建立standalone_jrebel.cmd,内容如下:
@echo off
set JAVA_OPTS=-agentpath:%REBEL_HOME%\lib\jrebel64.dll -Xms256m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m %JAVA_OPTS%
call "%~dp0\standalone.bat" %*
每次启动应用使用这个脚本启动,启动后控制台出现如下内容说明启动成功:
2016-11-26 10:36:42 JRebel: Starting logging to file: C:\Users\AL\.jrebel\jrebel.log
2016-11-26 10:36:42 JRebel:
2016-11-26 10:36:42 JRebel: #############################################################
2016-11-26 10:36:42 JRebel:
2016-11-26 10:36:42 JRebel: JRebel Agent 7.0.0 (201611081555)
2016-11-26 10:36:42 JRebel: (c) Copyright ZeroTurnaround AS, Estonia, Tartu.