java - IntelliJ IDEA 和 JRebel 不重新加载类

标签 java plugins intellij-idea jrebel

我尝试在简单的结构项目中使用 IDEA 的 JRebel 插件:

Test/
├── out
│   └── production
│       └── Test
│           ├── App.class
│           └── rebel.xml
├── src
│   ├── App.java
│   └── rebel.xml
└── Test.iml

rebel.xml:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">

    <classpath>
        <dir name="/home/ant/Documents/Java_Projects/Test/out/production/Test">
        </dir>
    </classpath>

</application>

使用 JRebel 运行 -> App.java:

public class App {
    public static void main(String[] args) throws Exception {
        for (; ;) {
            System.out.println("Hello jrebel");
            Thread.sleep(1000);
        }
    }
}

JRebel 日志:

2014-02-25 17:46:55 JRebel: 
2014-02-25 17:46:55 JRebel: #############################################################
2014-02-25 17:46:55 JRebel: 
2014-02-25 17:46:55 JRebel:  JRebel 5.5 (201312230953)
2014-02-25 17:46:55 JRebel:  (c) Copyright ZeroTurnaround OU, Estonia, Tartu.
2014-02-25 17:46:55 JRebel: 
2014-02-25 17:46:55 JRebel:  Over the last 1 days JRebel prevented 
2014-02-25 17:46:55 JRebel:  at least 0 redeploys/restarts saving you about 0 hours.
2014-02-25 17:46:55 JRebel: 
2014-02-25 17:46:55 JRebel:  You are running with an evaluation license.
2014-02-25 17:46:55 JRebel:  You have 11 days until the license expires. 
2014-02-25 17:46:55 JRebel: 
2014-02-25 17:46:55 JRebel:  You will see this notification until you obtain a 
2014-02-25 17:46:55 JRebel:  full license for your installation. 
2014-02-25 17:46:55 JRebel: 
2014-02-25 17:46:55 JRebel:  Visit www.jrebel.com for instructions on obtaining    
2014-02-25 17:46:55 JRebel:  a full license. If you wish to continue your evaluation  
2014-02-25 17:46:55 JRebel:  please e-mail to <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dba8aeababb4a9af9ba1bea9b4afaea9b5baa9b4aeb5bff5b8b4b6" rel="noreferrer noopener nofollow">[email protected]</a>.             
2014-02-25 17:46:55 JRebel:                                                           
2014-02-25 17:46:55 JRebel:  If you think you should not see this message contact     
2014-02-25 17:46:55 JRebel:  <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="52212722223d2026122837203d2627203c33203d273c367c313d3f" rel="noreferrer noopener nofollow">[email protected]</a> or check that you have your   
2014-02-25 17:46:55 JRebel:  license file in the same directory as the JAR file.      
2014-02-25 17:46:55 JRebel: 
2014-02-25 17:46:55 JRebel:  The following plugins are disabled at the moment: 
2014-02-25 17:46:55 JRebel:  * Axis2 plugin (set -Drebel.axis2_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * Camel plugin (set -Drebel.camel_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * Click plugin (set -Drebel.click_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * Deltaspike plugin (set -Drebel.deltaspike_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * Eclipse RCP Plugin (set -Drebel.eclipse_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * JBoss7 EJB Plugin (set -Drebel.jboss7_ejb_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * JRuby Plugin (set -Drebel.jruby_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * Jersey plugin (set -Drebel.jersey_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * Log4j2 plugin (set -Drebel.log4j2_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * Mustache Plugin (set -Drebel.mustache_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * RESTlet plugin (set -Drebel.restlet_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * Seam-Wicket plugin (set -Drebel.seam_wicket_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * Spring Data Plugin (set -Drebel.spring_data_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * Thymeleaf Plugin (set -Drebel.thymeleaf_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * VRaptor plugin (set -Drebel.vraptor_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * Vaadin CDI utils plugin (set -Drebel.vaadin_cdiutils_plugin=true to enable)
2014-02-25 17:46:55 JRebel:  * WebObjects plugin (set -Drebel.webobjects_plugin=true to enable)
2014-02-25 17:46:55 JRebel: 
2014-02-25 17:46:55 JRebel: #############################################################
2014-02-25 17:46:55 JRebel: 
2014-02-25 17:46:55 JRebel: Directory '/home/ant/Documents/Java_Projects/Test/out/production/Test' will be monitored for changes.
Hello java
Hello java
Hello java
...

当我在 jrebel 上更改输出流中的 java 单词时

 System.out.println("Hello jrebel");

JRebel 不会重新加载更改。

出了什么问题?

最佳答案

在您的示例中,执行永远不会脱离 while 循环,因此它永远不会脱离该方法。方法在执行过程中无法被替换,因此要重新加载,执行应首先跳出该方法。

这样做:

  public class App {
    public static void main(String[] args) throws Exception {
      Bean bean = new Bean();
      for (; ;) {
        bean.foo();
        Thread.sleep(1000);
      }
    }
  }

 public class Bean {
   public void foo(){
     System.out.println("Hello jrebel");
   }
 }

现在您可以更改 Bean 类中的任何内容,但不能在 while 循环内更改 - 该类可以重新加载,但该方法永远不会退出,因此永远没有机会执行新指令。

顺便说一句,不要忘记编译更改后的类。

关于java - IntelliJ IDEA 和 JRebel 不重新加载类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22019451/

相关文章:

java - 在 IntelliJ IDEA 中抑制 "variable is never assigned"警告

javascript - WebStorm 将 React render() 函数标记为未使用字段

java - 开发 TCP 通信器的最佳实践

plugins - 如何在 Firebreath 插件中获取 NPP 实例?

javascript - 从两种颜色创建随机图案

c# - Visual Studio 2010 插件 - 将上下文菜单添加到解决方案资源管理器

java - java、hibernate.initialize() 的奇怪行为

java - ejb3 : mapping many-to-many relationship jointable with a simple primary key

Java打印数组中的某些字符

java - 我可以使用 Mapstruct 在单个 Java 类中调用多个外部映射器吗?