2

I'm developing a web application and I run Jetty as the development and testing environment when I develop under Eclipse.

When I make changes to Java classes, Eclipse automatically compiles them to the build directory, but Jetty won't see the changes until I stop and start the server. I know that Jetty supports "hot deployment" using ContextDeployer that will refresh updated application contexts, but it relies on a context file in a context directory being updated - which is not very useful in my case.

Is there a way to set up Jetty so that it will reload the web app when any of the classes it uses is updated?

My current jetty.xml looks something like this:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
    <Configure id="Server" class="org.eclipse.jetty.server.Server">
        <Set name="ThreadPool"><!-- bla bla --></Set>
        <Call name="addConnector"><!-- bla bla --></Call>
        <Set name="handler">
          <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
            <Set name="handlers">
             <Array type="org.eclipse.jetty.server.Handler">
               <Item>
                 <New id="webapp" class="org.eclipse.jetty.webapp.WebAppContext">
                   <Set name="displayName">My Web App</Set>
                   <Set name="resourceBase">src/main/webapp</Set>
                   <Set name="descriptor">src/main/webapp/WEB-INF/web.xml</Set>
                   <Set name="contextPath">/mywebapp</Set>
                 </New>
               </Item>
               <Item>
                 <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
               </Item>
             </Array>
            </Set>
          </New>
        </Set>
    </Configure>
Guss
  • 30,470
  • 17
  • 104
  • 128

2 Answers2

3

We have not found a way of doing this (aside from implementing our own version of the org.eclipse.jetty.deploy.providers.WebAppProvider).

We have configured jetty to hot deploy webapps from the webapps folder (property monitoredDirName of the WebappDeployer).

Then to hot deploy, I recreate my link in this folder to the src/main/webapp folder of my Eclipse project. The linked must be suffixed .war.

Not really automatic but good enough and avoids a Jetty restart.

If you go the route of re-implementing a WebappDeployer, I would not monitor the changes in .class files - they change too much when compiled by Eclipse, particularly in the case of automatic builds. I would implement a 'Tomcat like' solution by monitoring changes to the web.xml file. Then a dummy change saved to this file from Eclipse would trigger a redeployment.

Bruno Grieder
  • 28,128
  • 8
  • 69
  • 101
  • 1
    I've managed to use a similar solution without developing plugins for Jetty: I'm using a ContextProvider (http://wiki.eclipse.org/Jetty/Feature/ContextDeployer) with a context.xml file to setup the webapp. Its important to set the location of the application classes in the context file (using ``) and not in the Eclipse launch configuration. Then I've added an Ant builder to the project configuration that on auto-builds uses the `touch` task to update the context.xml and cause the context to redeploy. – Guss Mar 19 '12 at 10:34
  • @jesse the problem with manipulating context.xml files is that they are outside the war. This complicates build and deployment – Bruno Grieder Mar 19 '12 at 13:58
  • in that case look at using the jetty-maven-plugin coupled with webby for the eclipse plugin – jesse mcconnell Mar 19 '12 at 15:07
  • jetty-maven-plugin is great for development. Building a complex app backed by a Maven repo fed by continuous integration builds is a different story. We had to ditch Tomcat because (among others) there is no way in the latest version to specify the webapp context root inside the war. Jesse, I hope Jetty is not going this route. – Bruno Grieder Mar 19 '12 at 16:28
0

It is also possible to configure your jetty app with maven and starting periodical builds with Jenkins (even every couple of seconds, depending on the maschine you are working on)

Julian Dehne
  • 83
  • 1
  • 3