简体   繁体   中英

Tell Jetty to reload on webapp change, not context.xml change

I have jetty running with some context.xml:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
      <Set name="war">path/to/webapp</Set>
      <Set name="contextPath">/</Set>
</Configure>

(The path is not default.) The webapp is rebuilt upon every change, but still I need to fake some write access to the context.xml to make jetty reload the webapp.

Is there a way to tell jetty to reload the webapp upon change?

Jasper,

I found a way to make this work (thanks to this question ). If you run Jetty in debug mode and connect the Eclipse debugger to it, the VM will hot-swap the class changes instantly.

Run Jetty with (I'm using Jetty 8 w/ JDK 6):

java -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n -jar start.jar

and then create a standard Remote Debug configuration in Eclipse that looks like this: 在此输入图像描述

and hit "Debug". Even if you don't plan on debugging anything, having the debugger connected to the remote Jetty VM will cause the class changes to deployed in real time.

The only thing you should be aware of is the limitations of the VM's ability to hot-swap a class. The "shape" of the class cannot change, so any new class members defined or new methods and you'll need to reload the web context (just "touch" the context's XML file and Jetty will reload it).

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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