Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Jetty/Feature/Jetty Maven Plugin"

< Jetty‎ | Feature
(New page: {{Jetty Feature | introduction = The Jetty Maven plugin is useful for rapid development and testing. It can be configured to periodically scan for changes and automatically redeploy the ...)
 
Line 1: Line 1:
 
{{Jetty Feature  
 
{{Jetty Feature  
 
| introduction =  
 
| introduction =  
The Jetty Maven plugin is useful for rapid development and testing. It can be configured to periodically scan for changes and automatically redeploy the webapp. This makes the development cycle more productive by eliminating the build and deploy steps: you use your IDE to make changes to the project, and the running web container will automatically pick them up, allowing you to test them straight away.
+
The Jetty Maven plugin is useful for rapid development and testing. It can be added to any webapp project which is structured according to the usual Maven defaults.
 +
 
 +
The plugin can then periodically scan your project for changes and automatically redeploy the webapp if any are found. This makes the development cycle more productive by eliminating the build and deploy steps: you use your IDE to make changes to the project, and the running web container will automatically pick them up, allowing you to test them straight away.
  
 
| body =  
 
| body =  
 
=== Quick Start ===
 
=== Quick Start ===
  
To run Jetty on a webapp project which is structured according to the usual Maven defaults, add jetty-maven-plugin to your pom.xml:
+
First, add jetty-maven-plugin to your pom.xml definition:
  
 
<source lang="xml">
 
<source lang="xml">
Line 15: Line 17:
 
</source>
 
</source>
  
Then, in the same directory as your root pom.xml, simply type:
+
Then, from the same directory as your root pom.xml, simply type:
  
 
   mvn jetty:run
 
   mvn jetty:run
Line 21: Line 23:
 
This will start Jetty and serve up your project on http://localhost:8080/.
 
This will start Jetty and serve up your project on http://localhost:8080/.
  
{{note|text= The usual Maven defaults are as follows:
+
Jetty will continue to run until you stop it. While it runs, it will periodically scan for changes to your project files, so if you save changes and recompile your class files, Jetty will redeploy your webapp, and you can instantly test the changes you just made.
 +
 
 +
=== Stopping the Plugin from the Command Line ===
 +
 
 +
You can terminate the plugin with a <tt><ctrl-c></tt> in the terminal window where it is running, or by executing the <tt>stop</tt> goal in another terminal window.
 +
 
 +
If you wish to be able to use <tt>mvn jetty:stop</tt> then you need to configure the plugin with a special port number and key that you also supply on the <tt>stop</tt> command:
 +
<source lang="xml">
 +
<plugin>
 +
  <groupId>org.mortbay.jetty</groupId>
 +
  <artifactId>jetty-maven-plugin</artifactId>
 +
  <configuration>
 +
    <stopPort>9966</stopPort>
 +
    <stopKey>foo</stopKey>
 +
  </configuration>
 +
</plugin>
 +
</source>
 +
 
 +
Then, while Jetty is running, type:
 +
 
 +
    mvn jetty:stop
 +
 
 +
The <code><stopPort></code> must be free on the machine you are running on. If this is not the case, you will get an "Address already in use" error message after the "Started SelectedChannelConnector ..." message.
 +
 
 +
=== Plugin Goals ===
 +
The <tt>jetty:run</tt> goal only runs on assembled webapps which follow the usual Maven defaults, as follows:
 +
 
 
* resources in <tt>${basedir}/src/main/webapp</tt>
 
* resources in <tt>${basedir}/src/main/webapp</tt>
 
* classes in <tt>${project.build.outputDirectory}</tt>
 
* classes in <tt>${project.build.outputDirectory}</tt>
* <tt>web.xml</tt> in <tt>${basedir}/src/main/webapp/WEB-INF/</tt>}}
+
* <tt>web.xml</tt> in <tt>${basedir}/src/main/webapp/WEB-INF/</tt>
}}
+
  
Jetty will continue to run until you stop it. While it runs, it will periodically scan for changes to your project files, so if you save changes and recompile your class files, Jetty will redeploy your webapp, and you can instantly test the changes you just made.  
+
If, for whatever reason, you cannot run on an unassembled webapp, the plugin also supports the <tt>jetty:run-war</tt> and <tt>jetty:run-exploded</tt> goal, which work on  These are discussed further below.
  
Stop it now by hitting <tt>CTRL-C</tt>.
+
<!-- Need to  update this once we have these pages up on the jetty.mortbay.org for Jetty 7
 +
More information on each of the goals is available at [mvn jetty:run page|http://jetty.mortbay.org/maven-plugin/run-mojo.html], [mvn jetty:run-exploded page|http://jetty.mortbay.org/maven-plugin/run-exploded-mojo.html], [mvn jetty:run-war page|http://jetty.mortbay.org/maven-plugin/run-war-mojo.html] and the [Jetty Documentation].
 +
-->
 +
 
 +
=== Automatic Plugin Execution ===
 +
The plugin's automatic plugin execution is useful for doing unit testing (for example). You can automatically have your webapp started at the beginning of the tests, and stopped at the end rather than manually executing <tt>mvn jetty:run</tt> on the command line.
 +
 
 +
To do this, you need to set up a couple of <code><execution></code> scenarios for the Jetty plugin and use the <code><daemon>true</daemon></code> configuration option to force Jetty to only execute while Maven is running, instead of running indefinitely.
 +
 
 +
The <code>pre-integration-test</code> and <code>post-integration-test</code> Maven build phases can be used to trigger the execution and termination of Jetty:
 +
 
 +
<source lang="xml">
 +
<plugin>
 +
  <groupId>org.mortbay.jetty</groupId>
 +
  <artifactId>jetty-maven-plugin</artifactId>
 +
  <configuration>
 +
    <scanIntervalSeconds>10</scanIntervalSeconds>
 +
    <stopKey>foo</stopKey>
 +
    <stopPort>9999</stopPort>
 +
  </configuration>
 +
  <executions>
 +
    <execution>
 +
      <id>start-jetty</id>
 +
      <phase>pre-integration-test</phase>
 +
      <goals>
 +
        <goal>run</goal>
 +
      </goals>
 +
      <configuration>
 +
      <scanIntervalSeconds>0</scanIntervalSeconds>
 +
      <daemon>true</daemon>
 +
      </configuration>
 +
    </execution>
 +
    <execution>
 +
      <id>stop-jetty</id>
 +
      <phase>post-integration-test</phase>
 +
      <goals>
 +
        <goal>stop</goal>
 +
      </goals>
 +
    </execution>
 +
  </executions>
 +
</plugin>
 +
</source>
 +
 
 +
{{note|text=Maven by default looks for plugins with a groupId of org.apache.maven.plugins, even if the groupId is declared differently as above. In order to instruct Maven to look for the plugin in the groupId as defined, set a plugin group in a profile in settings.xml like so:
 +
<pre>
 +
<profile>
 +
  ...
 +
  <pluginGroups>
 +
    <pluginGroup>org.mortbay.jetty</pluginGroup>
 +
  </pluginGroups>
 +
</profile>
 +
</pre>}}
 +
 
 +
 
 +
}}

Revision as of 07:09, 10 August 2009



Introduction

The Jetty Maven plugin is useful for rapid development and testing. It can be added to any webapp project which is structured according to the usual Maven defaults.

The plugin can then periodically scan your project for changes and automatically redeploy the webapp if any are found. This makes the development cycle more productive by eliminating the build and deploy steps: you use your IDE to make changes to the project, and the running web container will automatically pick them up, allowing you to test them straight away.

Feature

Quick Start

First, add jetty-maven-plugin to your pom.xml definition:

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
</plugin>

Then, from the same directory as your root pom.xml, simply type:

 mvn jetty:run

This will start Jetty and serve up your project on http://localhost:8080/.

Jetty will continue to run until you stop it. While it runs, it will periodically scan for changes to your project files, so if you save changes and recompile your class files, Jetty will redeploy your webapp, and you can instantly test the changes you just made.

Stopping the Plugin from the Command Line

You can terminate the plugin with a <ctrl-c> in the terminal window where it is running, or by executing the stop goal in another terminal window.

If you wish to be able to use mvn jetty:stop then you need to configure the plugin with a special port number and key that you also supply on the stop command:

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <configuration>
    <stopPort>9966</stopPort>
    <stopKey>foo</stopKey>
  </configuration>
</plugin>

Then, while Jetty is running, type:

   mvn jetty:stop

The <stopPort> must be free on the machine you are running on. If this is not the case, you will get an "Address already in use" error message after the "Started SelectedChannelConnector ..." message.

Plugin Goals

The jetty:run goal only runs on assembled webapps which follow the usual Maven defaults, as follows:

  • resources in ${basedir}/src/main/webapp
  • classes in ${project.build.outputDirectory}
  • web.xml in ${basedir}/src/main/webapp/WEB-INF/

If, for whatever reason, you cannot run on an unassembled webapp, the plugin also supports the jetty:run-war and jetty:run-exploded goal, which work on These are discussed further below.


Automatic Plugin Execution

The plugin's automatic plugin execution is useful for doing unit testing (for example). You can automatically have your webapp started at the beginning of the tests, and stopped at the end rather than manually executing mvn jetty:run on the command line.

To do this, you need to set up a couple of <execution> scenarios for the Jetty plugin and use the <daemon>true</daemon> configuration option to force Jetty to only execute while Maven is running, instead of running indefinitely.

The pre-integration-test and post-integration-test Maven build phases can be used to trigger the execution and termination of Jetty:

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <configuration>
    <scanIntervalSeconds>10</scanIntervalSeconds>
    <stopKey>foo</stopKey>
    <stopPort>9999</stopPort>
  </configuration>
  <executions>
    <execution>
      <id>start-jetty</id>
      <phase>pre-integration-test</phase>
      <goals>
        <goal>run</goal>
      </goals>
      <configuration>
       <scanIntervalSeconds>0</scanIntervalSeconds>
       <daemon>true</daemon>
      </configuration>
    </execution>
    <execution>
      <id>stop-jetty</id>
      <phase>post-integration-test</phase>
      <goals>
        <goal>stop</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Note.png

Back to the top