public void doStart() {
    try {
      TaskLog.logWithTimestamp("Starting web application " + this.getDescriptor());
      if (jettyEnvXml != null && jettyEnvXml.exists())
        envConfiguration.setJettyEnvXml(Resource.toURL(jettyEnvXml));

      ClassLoader parentLoader = this.getClass().getClassLoader();
      if (parentLoader instanceof AntClassLoader)
        parentLoader = new AntURLClassLoader((AntClassLoader) parentLoader);

      setClassLoader(new WebAppClassLoader(parentLoader, this));
      if (attributes != null && attributes.getAttributes() != null) {
        for (Attribute a : attributes.getAttributes()) setAttribute(a.getName(), a.getValue());
      }

      // apply a context xml file if one was supplied
      if (contextXml != null) {
        XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.toURL(contextXml));
        TaskLog.log("Applying context xml file " + contextXml);
        xmlConfiguration.configure(this);
      }

      super.doStart();
    } catch (Exception e) {
      TaskLog.log(e.toString());
    }
  }
  /**
   * Set up the execution classpath for Jasper.
   *
   * <p>Put everything in the classesDirectory and all of the dependencies on the classpath.
   *
   * @returns a list of the urls of the dependencies
   * @throws Exception
   */
  private List<URL> setUpWebAppClassPath() throws Exception {
    // add any classes from the webapp
    List<URL> urls = new ArrayList<URL>();
    String classesDir = classesDirectory.getCanonicalPath();
    classesDir = classesDir + (classesDir.endsWith(File.pathSeparator) ? "" : File.separator);
    urls.add(Resource.toURL(new File(classesDir)));

    if (getLog().isDebugEnabled()) getLog().debug("Adding to classpath classes dir: " + classesDir);

    // add the dependencies of the webapp (which will form WEB-INF/lib)
    for (Iterator<Artifact> iter = project.getArtifacts().iterator(); iter.hasNext(); ) {
      Artifact artifact = (Artifact) iter.next();

      // Include runtime and compile time libraries
      if (!Artifact.SCOPE_TEST.equals(artifact.getScope())
          && !Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) {
        String filePath = artifact.getFile().getCanonicalPath();
        if (getLog().isDebugEnabled())
          getLog().debug("Adding to classpath dependency file: " + filePath);

        urls.add(Resource.toURL(artifact.getFile()));
      }
    }
    return urls;
  }
  public void doStart() throws Exception {
    // Set up the pattern that tells us where the jars are that need scanning for
    // stuff like taglibs so we can tell jasper about it (see TagLibConfiguration)

    // Allow user to set up pattern for names of jars from the container classpath
    // that will be scanned - note that by default NO jars are scanned
    String tmp = _containerIncludeJarPattern;
    if (tmp == null || "".equals(tmp))
      tmp = (String) getAttribute(WebInfConfiguration.CONTAINER_JAR_PATTERN);

    tmp = addPattern(tmp, DEFAULT_CONTAINER_INCLUDE_JAR_PATTERN);
    setAttribute(WebInfConfiguration.CONTAINER_JAR_PATTERN, tmp);

    // Allow user to set up pattern of jar names from WEB-INF that will be scanned.
    // Note that by default ALL jars considered to be in WEB-INF will be scanned - setting
    // a pattern restricts scanning
    if (_webInfIncludeJarPattern != null)
      setAttribute(WebInfConfiguration.WEBINF_JAR_PATTERN, _webInfIncludeJarPattern);

    // Set up the classes dirs that comprises the equivalent of WEB-INF/classes
    if (_testClasses != null) _webInfClasses.add(_testClasses);
    if (_classes != null) _webInfClasses.add(_classes);

    // Set up the classpath
    _classpathFiles = new ArrayList<File>();
    _classpathFiles.addAll(_webInfClasses);
    _classpathFiles.addAll(_webInfJars);

    // Initialize map containing all jars in /WEB-INF/lib
    _webInfJarMap.clear();
    for (File file : _webInfJars) {
      // Return all jar files from class path
      String fileName = file.getName();
      if (fileName.endsWith(".jar")) _webInfJarMap.put(fileName, file);
    }

    if (this._jettyEnvXml != null)
      _envConfig.setJettyEnvXml(Resource.toURL(new File(this._jettyEnvXml)));

    // CHECK setShutdown(false);
    super.doStart();
  }
  public void doStart() throws Exception {
    // Set up the pattern that tells us where the jars are that need scanning for
    // stuff like taglibs so we can tell jasper about it (see TagLibConfiguration)
    String tmp =
        (String) getAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern");

    tmp = addPattern(tmp, ".*/.*jsp-api-[^/]*\\.jar$");
    tmp = addPattern(tmp, ".*/.*jsp-[^/]*\\.jar$");
    tmp = addPattern(tmp, ".*/.*taglibs[^/]*\\.jar$");
    tmp = addPattern(tmp, ".*/.*jstl[^/]*\\.jar$");
    tmp = addPattern(tmp, ".*/.*jsf-impl-[^/]*\\.jar$"); // add in 2 most popular jsf impls
    tmp = addPattern(tmp, ".*/.*javax.faces-[^/]*\\.jar$");
    tmp = addPattern(tmp, ".*/.*myfaces-impl-[^/]*\\.jar$");

    setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", tmp);

    // Set up the classes dirs that comprises the equivalent of WEB-INF/classes
    if (testClasses != null) webInfClasses.add(testClasses);
    if (classes != null) webInfClasses.add(classes);

    // Set up the classpath
    classpathFiles = new ArrayList<File>();
    classpathFiles.addAll(webInfClasses);
    classpathFiles.addAll(webInfJars);

    // Initialize map containing all jars in /WEB-INF/lib
    webInfJarMap.clear();
    for (File file : webInfJars) {
      // Return all jar files from class path
      String fileName = file.getName();
      if (fileName.endsWith(".jar")) webInfJarMap.put(fileName, file);
    }

    if (this.jettyEnvXml != null)
      envConfig.setJettyEnvXml(Resource.toURL(new File(this.jettyEnvXml)));

    // setShutdown(false);
    super.doStart();
  }
  /** @see org.eclipse.jetty.maven.plugin.AbstractJettyMojo#configureWebApplication() */
  public void configureWebApplication() throws Exception {
    super.configureWebApplication();

    // Set up the location of the webapp.
    // There are 2 parts to this: setWar() and setBaseResource(). On standalone jetty,
    // the former could be the location of a packed war, while the latter is the location
    // after any unpacking. With this mojo, you are running an unpacked, unassembled webapp,
    // so the two locations should be equal.
    Resource webAppSourceDirectoryResource =
        Resource.newResource(webAppSourceDirectory.getCanonicalPath());
    if (webApp.getWar() == null) webApp.setWar(webAppSourceDirectoryResource.toString());

    if (webApp.getBaseResource() == null) webApp.setBaseResource(webAppSourceDirectoryResource);

    if (classesDirectory != null) webApp.setClasses(classesDirectory);
    if (useTestScope && (testClassesDirectory != null)) webApp.setTestClasses(testClassesDirectory);

    webApp.setWebInfLib(getDependencyFiles());

    // get copy of a list of war artifacts
    Set<Artifact> matchedWarArtifacts = new HashSet<Artifact>();

    // make sure each of the war artifacts is added to the scanner
    for (Artifact a : getWarArtifacts()) extraScanTargets.add(a.getFile());

    // process any overlays and the war type artifacts
    List<Overlay> overlays = new ArrayList<Overlay>();
    for (OverlayConfig config : warPluginInfo.getMavenWarOverlayConfigs()) {
      // overlays can be individually skipped
      if (config.isSkip()) continue;

      // an empty overlay refers to the current project - important for ordering
      if (config.isCurrentProject()) {
        Overlay overlay = new Overlay(config, null);
        overlays.add(overlay);
        continue;
      }

      // if a war matches an overlay config
      Artifact a = getArtifactForOverlay(config, getWarArtifacts());
      if (a != null) {
        matchedWarArtifacts.add(a);
        SelectiveJarResource r =
            new SelectiveJarResource(
                new URL("jar:" + Resource.toURL(a.getFile()).toString() + "!/"));
        r.setIncludes(config.getIncludes());
        r.setExcludes(config.getExcludes());
        Overlay overlay = new Overlay(config, r);
        overlays.add(overlay);
      }
    }

    // iterate over the left over war artifacts and unpack them (without include/exclude processing)
    // as necessary
    for (Artifact a : getWarArtifacts()) {
      if (!matchedWarArtifacts.contains(a)) {
        Overlay overlay =
            new Overlay(
                null,
                Resource.newResource(
                    new URL("jar:" + Resource.toURL(a.getFile()).toString() + "!/")));
        overlays.add(overlay);
      }
    }

    webApp.setOverlays(overlays);

    // if we have not already set web.xml location, need to set one up
    if (webApp.getDescriptor() == null) {
      // Has an explicit web.xml file been configured to use?
      if (webXml != null) {
        Resource r = Resource.newResource(webXml);
        if (r.exists() && !r.isDirectory()) {
          webApp.setDescriptor(r.toString());
        }
      }

      // Still don't have a web.xml file: try the resourceBase of the webapp, if it is set
      if (webApp.getDescriptor() == null && webApp.getBaseResource() != null) {
        Resource r = webApp.getBaseResource().addPath("WEB-INF/web.xml");
        if (r.exists() && !r.isDirectory()) {
          webApp.setDescriptor(r.toString());
        }
      }

      // Still don't have a web.xml file: finally try the configured static resource directory if
      // there is one
      if (webApp.getDescriptor() == null && (webAppSourceDirectory != null)) {
        File f = new File(new File(webAppSourceDirectory, "WEB-INF"), "web.xml");
        if (f.exists() && f.isFile()) {
          webApp.setDescriptor(f.getCanonicalPath());
        }
      }
    }
    getLog().info("web.xml file = " + webApp.getDescriptor());
    getLog().info("Webapp directory = " + webAppSourceDirectory.getCanonicalPath());
  }