How to let jetty block the request when reloading modified classes?
Asked Answered
A

1

6

I'm using dcevm + run-jetty-run + livereload , try to develop a web app without restarting jetty when modifing java sources.

Everything works fine. When I modified a java class, livereload monitored the change, and triggered the browser refreshing opened pages to see the modified result.

But I found it still not that convenient: When browser reloads, dcevm and jetty may have not reloaded that modified classes yet. I have to manually refresh the page again, but I'm not sure if it shows the modified result this time, without checking the content carefully.

So I wonder is there any way to let jetty blocks the request when I modified some classes and dcevm is reloading. It will make sure the pages displayed are always modified.

Auctioneer answered 24/4, 2012 at 5:19 Comment(0)
R
1

It's maybe too hacky for your palate, but you could insert a static initialization snippet in your Java sources to update a known, separate file after reloading. Than livereload can watch that separate file instead of letting it work directly on .java sources.

Something along the lines of:

public class ReloadUtils {
  public static void notifyUpdate(String className) {
    String baseDir = System.getProperty("DEV_MODE_BASEDIR") + "/";
    File file = new File(baseDir + className + ".updated");
    FileWriter fw = new FileWriter(file.getAbsoluteFile(), false); // overwrite instead of append
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write(Long.toString(System.currentTimeMillis()));
    bw.close();
  }
}

public class Reloadable {

  private final static boolean DEV_MODE = System.getProperty("DEV_MODE").equals("true");

  static {
    // static finals trigger most compilers to remove the statements in this case
    if (DEV_MODE) { 
      ReloadUtils.notifyUpdate(Reloadable.class.getName());
    }
  }

  /* lots of useful stuff */
}
Recurrent answered 26/9, 2013 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.