简体   繁体   English

Jetty中的热代码部署

[英]Hot code deployment in Jetty

I am writing a Java EE application, using Jetty as the app server for convenience during development. 我正在编写一个Java EE应用程序,在开发过程中使用Jetty作为应用程序服务器。 Although (re)deployment is fast, I'd like if it was possible for Java code changes to be reflected immediately in the running server without restarting. 虽然(重新)部署速度很快,但我希望Java代码更改能够立即反映在正在运行的服务器中,而无需重新启动。 (I'm already using the useFileMappedBuffer setting to see immediate changes to statically served content). (我已经使用useFileMappedBuffer设置来查看对静态服务内容的即时更改)。

I've seen questions about using the Maven Jetty plugin and setting scanInterval in order to redeploy a web context, but that's not what I want to do. 我已经看到有关使用Maven Jetty插件和设置scanInterval以重新部署Web上下文的问题,但这不是我想要做的。 My Jetty server is started from within a Java application in Eclipse and I'd like code changes to be immediately reflected in the running server, as is possible with ordinary Java applications in Eclipse. 我的Jetty服务器是从Eclipse中的Java应用程序启动的,我希望代码更改能够立即反映在正在运行的服务器中,就像Eclipse中的普通Java应用程序一样。 I'm running the code "in place", ie not building and deploying a WAR file first. 我正在运行“就地”代码,即不首先构建和部署WAR文件。

I realise that web apps have their own class loaders in order to conform to the servlet spec, but I don't mind risking non-standard behaviour to get changes deployed more rapidly in development. 我意识到Web应用程序有自己的类加载器,以符合servlet规范,但我不介意冒着非标准行为冒险在开发中更快地部署更改。 I've tried using WebAppContext.setClassLoader to set the classloader to a "normal" classloader but to no avail. 我已经尝试使用WebAppContext.setClassLoader将类加载器设置为“普通”类加载器,但无济于事。

Is it possible to do what I want? 有可能做我想要的吗? I believe JRebel claims to do it, but what's it doing that I'm not? 我相信JRebel声称要做到这一点,但它做了什么,我不是?

If you connect to Jetty using remote debug from Eclipse, Hot code replace should be possible. 如果使用Eclipse中的远程调试连接到Jetty,则应该可以进行热代码替换

Remote debugging is enabled by adding following to Jetty start script: 通过向Jetty启动脚本添加以下内容来启用远程调试:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787

Even the ordinary Java application needs to be restarted to see code changes. 甚至普通的Java应用程序也需要重新启动以查看代码更改。

Basically your options are: 基本上你的选择是:

  1. Restart Jetty (you said you don't want that). 重启Jetty(你说你不想那样)。
  2. Make Jetty scan for application changes and allow hot redeploy if changes are detected (you said you don't want that). 使Jetty扫描应用程序更改,并在检测到更改时允许热重新部署(您说您不希望这样做)。
  3. Attach a remote debugger which then does hot-swap your code changes (see answer of Amila). 连接一个远程调试器,然后热插拔代码更改(请参阅Amila的答案)。 This is limited to method body changes and therefore not really useful. 这仅限于方法体改变,因此不太有用。
  4. Use JRebel which provides a useful hot-swap implementation and also can pick up configuration changes for many frameworks. 使用JRebel提供有用的热交换实现,也可以为许多框架选择配置更改。
  5. Use a web framework which implements a proprietary hot-swap implementation based on throw-away-classloaders (eg Tapestry or Civilian ). 使用Web框架实现基于抛弃类加载器(例如TapestryCivilian )的专有热交换实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM