1
//========================================================================
2
//$Id: Jetty6RunMojo.java 2299 2008-01-03 23:40:50Z janb $
3
//Copyright 2000-2004 Mort Bay Consulting Pty. Ltd.
4
//------------------------------------------------------------------------
5
//Licensed under the Apache License, Version 2.0 (the "License");
6
//you may not use this file except in compliance with the License.
7
//You may obtain a copy of the License at
8
//http://www.apache.org/licenses/LICENSE-2.0
9
//Unless required by applicable law or agreed to in writing, software
10
//distributed under the License is distributed on an "AS IS" BASIS,
11
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//See the License for the specific language governing permissions and
13
//limitations under the License.
14
//========================================================================
16
package org.mortbay.jetty.plugin;
20
import org.apache.maven.plugin.MojoExecutionException;
21
import org.apache.maven.plugin.MojoFailureException;
22
import org.mortbay.jetty.Connector;
23
import org.mortbay.jetty.Handler;
24
import org.mortbay.jetty.RequestLog;
25
import org.mortbay.jetty.Server;
26
import org.mortbay.jetty.handler.ContextHandler;
27
import org.mortbay.jetty.handler.ContextHandlerCollection;
28
import org.mortbay.jetty.handler.HandlerCollection;
29
import org.mortbay.jetty.plugin.util.JettyPluginServer;
30
import org.mortbay.jetty.security.UserRealm;
31
import org.mortbay.xml.XmlConfiguration;
35
* This goal is used in-situ on a Maven project without first requiring that the project
36
* is assembled into a war, saving time during the development cycle.
37
* The plugin forks a parallel lifecycle to ensure that the "compile" phase has been completed before invoking Jetty. This means
38
* that you do not need to explicity execute a "mvn compile" first. It also means that a "mvn clean jetty:run" will ensure that
39
* a full fresh compile is done before invoking Jetty.
42
* Once invoked, the plugin can be configured to run continuously, scanning for changes in the project and automatically performing a
43
* hot redeploy when necessary. This allows the developer to concentrate on coding changes to the project using their IDE of choice and have those changes
44
* immediately and transparently reflected in the running web container, eliminating development time that is wasted on rebuilding, reassembling and redeploying.
47
* You may also specify the location of a jetty.xml file whose contents will be applied before any plugin configuration.
48
* This can be used, for example, to deploy a static webapp that is not part of your maven build.
51
* There is a <a href="run-mojo.html">reference guide</a> to the configuration parameters for this plugin, and more detailed information
52
* with examples in the <a href="http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin">Configuration Guide</a>.
57
* @requiresDependencyResolution runtime
58
* @execute phase="test-compile"
59
* @description Runs jetty6 directly from a maven project
61
public class Jetty6RunMojo extends AbstractJettyRunMojo
66
* List of connectors to use. If none are configured
67
* then the default is a single SelectChannelConnector at port 8080. You can
68
* override this default port number by using the system property jetty.port
69
* on the command line, eg: mvn -Djetty.port=9999 jetty:run
73
private Connector[] connectors;
77
* List of other contexts to set up. Optional.
80
private ContextHandler[] contextHandlers;
84
* List of security realms to set up. Optional.
87
private UserRealm[] userRealms;
92
* A RequestLog implementation to use for the webapp at runtime.
96
private RequestLog requestLog;
99
public Object getConfiguredRequestLog()
101
return this.requestLog;
109
* @see org.mortbay.jetty.plugin.AbstractJettyRunMojo#getConfiguredConnectors()
111
public Object[] getConfiguredConnectors()
113
return this.connectors;
121
* @see org.mortbay.jetty.plugin.AbstractJettyRunMojo#getConfiguredUserRealms()
123
public Object[] getConfiguredUserRealms()
125
return this.userRealms;
131
* @return Returns the contextHandlers.
133
public ContextHandler[] getConfiguredContextHandlers()
135
return this.contextHandlers;
142
* @see org.mortbay.jetty.plugin.AbstractJettyRunMojo#createServer()
144
public JettyPluginServer createServer()
146
return new Jetty6PluginServer();
150
public void finishConfigurationBeforeStart() throws Exception
152
Handler[] handlers = getConfiguredContextHandlers();
153
JettyPluginServer plugin=getServer();
154
Server server=(Server)plugin.getProxiedObject();
156
HandlerCollection contexts = (HandlerCollection)server.getChildHandlerByClass(ContextHandlerCollection.class);
158
contexts = (HandlerCollection)server.getChildHandlerByClass(HandlerCollection.class);
160
for (int i=0; (handlers != null) && (i < handlers.length); i++)
162
contexts.addHandler(handlers[i]);
169
public void applyJettyXml() throws Exception
171
if (getJettyXmlFile() == null)
174
getLog().info( "Configuring Jetty from xml configuration file = " + getJettyXmlFile() );
175
XmlConfiguration xmlConfiguration = new XmlConfiguration(getJettyXmlFile().toURL());
176
xmlConfiguration.configure(getServer().getProxiedObject());
182
public void execute() throws MojoExecutionException, MojoFailureException