views:

792

answers:

2

I am working with jetty hightide vesion 7 currently as a stand alone server. I have a simple web project with a couple of jsp's and backing classes that I am currently deploying in an unexploded war to the JETTY_HOME/webapps directory.

Currently, jetty easily picks up any static jsp/html changes. If I understand correctly, I can configure my app so that jetty will pick up any class changes without restarting the server? I currently have in my jetty-web.xml:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"&gt;

<!--
    This is the jetty specific web application configuration file. When
    starting a Web Application, the WEB-INF/web-jetty.xml file is looked
    for and if found, treated as a
    org.eclipse.jetty.server.server.xml.XmlConfiguration file and is
    applied to the org.eclipse.jetty.servlet.WebApplicationContext objet
-->

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Call class="org.eclipse.jetty.util.log.Log" name="debug">
    <Arg>executing jetty-web.xml</Arg>
</Call>
<Set name="contextPath">/SimpleDynamicProject</Set>

</Configure>

I also have created a SimpleDynamicProject.xml and put it in JETTY_HOME/contexts. This file contains:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"&gt;

<!--
    This is the jetty specific web application configuration file. When
    starting a Web Application, the WEB-INF/web-jetty.xml file is looked
    for and if found, treated as a
    org.eclipse.jetty.server.server.xml.XmlConfiguration file and is
    applied to the org.eclipse.jetty.servlet.WebApplicationContext objet
-->

<Configure class="org.eclipse.jetty.webapp.WebAppContext">

<Set name="contextPath">/SimpleDynamicProject</Set>
<Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/webapps/SimpleDynamicProject</Set>
</Configure>

I am also not sure how to correctly start Jetty in debug mode which I read was also needed. I have tried starting the server with:

java -Xdebug -jar start.jar OPTIONS=Server,jsp

and

java -Ddebug -jar start.jar OPTIONS=Server,jsp

This is the first time I've used jetty, but so far I really like it.

Thanks for the help.

+1  A: 

You need to define a ContextDeployer with a non-zero scan interval:

<Call name="addLifeCycle">
  <Arg>
    <New class="org.mortbay.jetty.deployer.ContextDeployer">
      <Set name="contexts"><Ref id="Contexts"/></Set>
      <Set name="configurationDir"><SystemProperty name="jetty.home" default="."/>/contexts</Set>
      <Set name="scanInterval">1</Set>
    </New>
  </Arg>
</Call>

Regarding debugging, I guess that what you have in mind is to connect a remote debugger using JPDA. For this, you'll need to set the -agentlib:jdwp option1:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

The configure your IDE debugger to connect on the specified port.

1 if the target VM is 5.0 or newer, -agentlib:jdwp is preferable over the -Xdebug and -Xrunjdwp options which are still supported though.

Pascal Thivent
Oh so I need to add that to my project jetty.xml file? I was trying to configure it inside of the context directory of the jetty server under myapp.xml for instance. Thanks for the debugging information as well!
Casey
@Casey Yes I think so (actually, I always use Jetty from Maven so I'm more used to configuring the maven plugin but the logic applies here too). BTW, the common way of recognizing a good answer is upvoting it ;-)
Pascal Thivent
A: 

If you want to use jetty maven plugin

   <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.25</version>
        <configuration>
            <scanIntervalSeconds>10</scanIntervalSeconds>
            <requestLog implementation="org.mortbay.jetty.NCSARequestLog">
                <!--
                          This doesn't do anything for Jetty, but is a workaround for a
                          Maven bug that prevents the requestLog from being set.
                      -->
                <append>true</append>
            </requestLog>
            <webApp>${basedir}/out/war/Spring2_5_6_war.war</webApp>
        </configuration>
    </plugin>
Maciek Kreft
This is in fact exactly what we are doing on our team now. This is almost all the configuration that is needed. Also, we are using tapestry5 and this combination of maven/jetty works extremely well with that.
Casey