在 5 分钟内通过 10 个简单步骤集成 JRebel 与 Liberty

WebSphere Liberty 使您在重新部署应用程序时无需每次都重新启动应用服务器。来自 ZeroTurnaroun 的 JRebel 为它提供了补充,使您能即时重新加载代码,而无需每次都重新部署或重新启动应用程序。它与 Liberty 和 WebSphere Developer Tools 无缝集成。

这篇快速教程将介绍下载 Liberty,设置一个服务器,安装 JRebel,然后展示它的实际应用。以下步骤将概述如何安装 Liberty 概要文件,但是如果您需要更多细节,可以查阅 入门文章和视频。

安装适合您使用的 Eclipse 版本的 WebSphere Developer Tools:


EMP-Liberty

下载并安装这些工具后,您需要安装 Liberty 概要文件运行时。选择 File > New > Other…, 然后选择 New Server向导。选择 Liberty 概要文件并单击 Next。


NewLibertyServer

单击 download and install 选项。


Profile

选择 Liberty profile V8.5.5.x Runtime 存储库站点并单击 Next, 然后标记用于安装的 CDI sample 。我们将使用此项目来看看 JRebel 的实际应用。


download
安装完成时,您将在您的环境中看到该服务器:


ServerRunning

5.我们还希望查看源代码,以便修改它并看到 JRebel 即时重新加载我们的更改。可以使用标准 Import WAR向导完成此任务。 CDI 示例应用程序 将位于刚安装的服务器的 dropins 目录中;比如 <root path to installed server>usrserverscdiSampledropinscdiApp.war:


ImportCDI
然后需要将您的来源链接到 Liberty 服务器中部署的应用程序。将 Enterprise Explorer 视图中的 cdiApp 项目拖放到您创建的 Liberty 服务器上。

启动该服务器并在浏览器中输入该应用程序的 URL http://localhost:9100/cdiApp/sample.jsp (只是为了确认一切正常!)。


CDI-Original

6.现在您已准备好从 Eclipse Market Place 安装 JRebel。但是在这么做之前,如果您还没有 JRebel 试用许可,可能需要获得一个。

访问 Eclipse Marketplace 时,搜索 JRebel。单击 Install 并按说明操作:


EMP-JRebel

7.Eclipse 重新启动时,您将被提示配置 JRebel:


JR-C-Prompt

单击 Open Config Center 日志,然后使用 Activate / Update License 选项激活 JRebel:


JR-Activate-Licence

8.为您的 Liberty 服务器启用 JRebel。这会关闭 Liberty 上的自动发布,但这没有关系,因为 JRebel 现在将为您执行该工作:


JR-Enabled-Liberty

9.最后一步是为我们的项目启用 JRebel:


JR-Enable-CDI

在您的服务器控制台中,您现在将看到 JRebel 已与您的 Liberty 服务器集成:


JRebel-Log

10.现在,让我们修改一下从注入的 bean 打印出的消息。打开 InjectedBean 类并更改该消息。在本例中,添加文本“Updated by Jrebel”。

@RequestScoped
public class InjectedBean {
	
    /**
     * @return a customized message for this bean
     */
    public String getValue() {
        return "Congratulations! You successfully used CDI to inject a bean at the request scope! updated by JRebel";
    }
    
}

当您在浏览器中刷新时,您会看到一条日志消息表明更改的类已重新加载:


JR-Log-Update

您的浏览器还将显示更新的消息:


CDI-Rebel

11.最后,让我们做一件 JVM 很难做(甚至做不到)的事,那就是向已加载的类中添加另一个方法 – 在本例中为我们注入的 bean:

    /**
     * @return a customized message for this bean
     */
    public String getValue() {
        return "Congratulations! You successfully used CDI to inject a bean at the request scope! " + getJRebelText();
    }
    
    private String getJRebelText() { 
    	return "Updated by JRebel (new method)"; 
    } 

JRebel 然后会即时重新加载此更改,现在刷新您的浏览器将显示调用了更新后的方法:


CDI-Rebel-NewMethod

就这么简单!JRebel 现在将负责对服务器更新您对代码执行的更改。可以在 ZeroTurnaround 网站上找到 JRebel 的更多信息。


在developerWorks上的相关资源:

使用 WebSphere Developer Tools for Eclipse 在 Liberty 上创建一个 Hello World 应用程序



本文翻译自:JRebel with Liberty in 5 minutes and 10 easy steps(2017-01-05)

The post 在 5 分钟内通过 10 个简单步骤集成 JRebel 与 Liberty appeared first on developerWorks Developer Center -- 中国(Beta).

文章来源:

Author:developerWorks中国
link:https://developer.ibm.com/cn/blog/2017/jrebel-liberty-5-minutes-10-easy-steps/