View Javadoc

1   package org.codehaus.mojo.tomcat;
2   
3   /*
4    * Copyright 2006 Mark Hobson.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.io.File;
20  import java.net.MalformedURLException;
21  
22  import org.apache.catalina.Context;
23  import org.apache.catalina.loader.WebappLoader;
24  import org.apache.catalina.startup.Embedded;
25  
26  /**
27   * Runs the current project as a packaged web application using an embedded Tomcat server.
28   * 
29   * @goal run-war
30   * @execute phase = "package"
31   * @requiresDependencyResolution runtime
32   * 
33   * @todo depend on war:exploded when MNG-1649 resolved
34   * 
35   * @author Mark Hobson <markhobson@gmail.com>
36   * @version $Id: RunWarMojo.java 6588 2008-03-28 12:22:57Z bentmann $
37   */
38  public class RunWarMojo extends AbstractRunMojo
39  {
40      // ----------------------------------------------------------------------
41      // Mojo Parameters
42      // ----------------------------------------------------------------------
43  
44      /**
45       * The path of the exploded WAR directory to run.
46       * 
47       * @parameter expression = "${project.build.directory}/${project.build.finalName}"
48       * @required
49       */
50      private File warDirectory;
51  
52      // ----------------------------------------------------------------------
53      // AbstractRunMojo Implementation
54      // ----------------------------------------------------------------------
55  
56      /*
57       * @see org.codehaus.mojo.tomcat.AbstractRunMojo#createContext(org.apache.catalina.startup.Embedded)
58       */
59      protected Context createContext( Embedded container ) throws MalformedURLException
60      {
61          // create context
62          Context context = container.createContext( getPath(), warDirectory.getAbsolutePath() );
63          context.setLoader( new WebappLoader() );
64  
65          return context;
66      }
67  }