maven+jetty+idea+jrebel 实现项目热部署

2,819 阅读2分钟

tags:

  • maven
  • jetty
  • idea
  • jrebel
  • java

maven+jetty+idea+jrebel 实现项目热部署

开发环境

开发过程中: 修改java或者工程文件 需要重新对工程进行build deploy耗时太久 到无法忍受

如何实现一次部署之后,后面的修改全部热部署呢?

  1. 使用jrebel实现
  2. web容器使用的是jetty
  3. 项目管理使用的maven
  4. ide使用的是idea

实现步骤

  1. 打开idea中的settings-->plugins 搜索jrebel --> browse repositories
  2. install 开始进入下载 下载完成之后应用上 并且重启idea
  3. 因为jrebel是收费软件 破解链接如下:http://blog.lanyus.com/archives/317.html 正常启动后的样式:

破解工具

激活路径
server地址:http://127.0.0.1:8888/lemon lemon为任意字符串 email: 随意输入

激活

  1. 对于需要热部署的项目进行如下操作 右击项目名称 选中jrebel生成配置文件 正确的配置文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>

<!--
  This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
  Refer to https://manuals.zeroturnaround.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd">

	<classpath>
		<dir name="C:/workspaces***************/target/classes"> <!--为项目的编译路径-->
		</dir>
	</classpath>

	<web>
		<link target="/">
			<dir name="C:/workspace**********src/main/webapp"><!--为项目的路径-->
			</dir>
		</link>
	</web>

</application>

  1. 在idea菜单栏中 选中view >tool 如下 将两个工具栏均展示出来:

view
6. 在jrebel中配置你需要热部署的项目 只需配置主工程即可 base等依赖据不需勾选:

jrebel
7. 配置完成之后会在启动脚本旁边出现两个图标 分别为jrebel run和jrebel debug:

8. 代码中需要将jetty自身的热部署禁用

<plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>8.1.16.v20140903</version>
        <configuration>
          <stopKey>stop</stopKey>
          <stopPort>9999</stopPort>
          <scanIntervalSeconds>0</scanIntervalSeconds><!--使用jetty自身的热部署:1 不用为0-->
          <contextXml>${project.basedir}/src/main/resources/jetty-context.xml</contextXml>
          <webApp>
            <contextPath>/</contextPath>
          </webApp>
          <connectors>
            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
              <port>8001</port>
              <maxIdleTime>60000</maxIdleTime>
            </connector>
          </connectors>
        </configuration>
      </plugin>
  1. 当点击jrebel debug时 启动log出现如下图内容则标志着配置成功

    部署

  2. 启动之后体验一下热部署吧 针对单个文件进行的热部署: ctrl+shift+f9 针对修改的所有文件进行的热部署: ctrl+f9 执行之前别忘记ctrl + s

  3. 当执行上面的命令是 出现如下的内容 则表示部署成功:

部署成功

log中输出

未经作者允许 请勿转载,谢谢 :)