/** {@inheritDoc} */
 public void configureClassLoader() throws Exception {
   // Try to load classes from WEB-INF directory first before looking in the
   // system classpath. This fixes problems when using extended spring features
   // like mail and only having the additional .jar files in the WEB-INF/lib
   // directory. Please note that for example the spring-support.jar file must
   // be copied to the WEB-INF/lib directory, too as it's classloader is used
   // to load the additional classes.
   _context.setParentLoaderPriority(false);
 }
Пример #2
0
  WebAppContext webApp()
      throws IOException, SAXException, ClassNotFoundException, UnavailableException {
    WebAppContext wac = new WebAppContext();
    configuration.setWebAppContext(wac);
    configuration.initialize(getWarFile());

    wac.setConfigurationClasses(
        new String[] {
          "org.mortbay.jetty.webapp.WebInfConfiguration",
          "org.mortbay.jetty.webapp.WebXmlConfiguration",
          "org.mortbay.jetty.webapp.JettyWebXmlConfiguration",
        });
    wac.setContextPath(new SystemEnvironment().getWebappContextPath());
    wac.setWar(getWarFile());
    wac.setParentLoaderPriority(new SystemEnvironment().getParentLoaderPriority());
    setCookieExpireIn2Weeks(wac);
    addExtraJarsToClasspath(wac);
    addJRubyContextInitParams(wac);
    addStopServlet(wac);

    return wac;
  }
Пример #3
0
  public static void main(String[] args) throws Exception {
    String name = args.length > 0 ? args[0] : "app";
    Mocker mocker = Mocker.init(name);
    String webXml = mocker.getWebXml();
    int port = mocker.getPort();

    File fapp = new File(APP_PATH);
    final Connector conn = new SelectChannelConnector();
    conn.setPort(port);
    conn.setMaxIdleTime(60000);
    conn.setHeaderBufferSize(20480); // 缺省4K, Chrome下可能会报错: 413 FULL head

    Listener listerner =
        new Listener() {

          @Override
          public void lifeCycleFailure(LifeCycle arg0, Throwable arg1) {
            logger.info("YDJT SYSTEM {} FAILED!!!", Application.VERSION);
          }

          @Override
          public void lifeCycleStarted(LifeCycle arg0) {
            logger.info("YDJT SYSTEM {} STARTED!", Application.VERSION);
          }

          @Override
          public void lifeCycleStarting(LifeCycle arg0) {
            logger.info("YDJT SYSTEM {} STARTING...", Application.VERSION);
          }

          @Override
          public void lifeCycleStopped(LifeCycle arg0) {
            logger.info("YDJT SYSTEM {} STOPPED!", Application.VERSION);
          }

          @Override
          public void lifeCycleStopping(LifeCycle arg0) {
            logger.info("YDJT SYSTEM {} STOPPING...", Application.VERSION);
          }
        };
    Server server = new Server();
    server.addLifeCycleListener(listerner);
    server.addConnector(conn);
    WebAppContext wapp = new WebAppContext(server, fapp.getCanonicalPath(), CONTEXT_PATH);

    HandlerCollection hc = new HandlerCollection();
    ContextHandlerCollection chc = new ContextHandlerCollection();
    hc.setHandlers(new Handler[] {chc, new DefaultHandler()});

    ContextDeployer cd = new ContextDeployer();
    cd.setContexts(chc);
    cd.setConfigurationDir(APP_PATH);
    cd.setDirectory(APP_PATH);
    cd.setScanInterval(5);

    wapp.setClassLoader(ClassLoader.getSystemClassLoader());
    wapp.setParentLoaderPriority(false);
    wapp.setExtractWAR(false);
    // setDescriptor() -- 使用其他文件作为web.xml
    // wapp.setDefaultsDescriptor(WEB_XML);
    // setWelcomeFiles()和web.xml中的welcome-file-list都没有用,
    // 因为/已定义在test-mvc的servlet-mapping中??
    wapp.setDescriptor(APP_PATH + "/WEB-INF/" + webXml);

    // server.addLifeCycle(wapp);
    server.addHandler(hc);
    server.start();
    server.join();
    wapp.start();
    server.addLifeCycle(cd);
  }
Пример #4
0
  private static void initWebappContext(Server server, Configs configs)
      throws IOException, URISyntaxException {
    web = new WebAppContext();

    if (configs.getParentLoaderPriority()) {
      System.err.println("ParentLoaderPriority enabled");
      web.setParentLoaderPriority(true);
    }

    web.setContextPath(configs.getContext());
    System.err.println("Context path:" + configs.getContext());
    web.setWar(configs.getWebAppDir());

    /** open a way to set the configuration classes */
    List<String> configurationClasses = configs.getConfigurationClassesList();
    if (configurationClasses.size() != 0) {
      web.setConfigurationClasses(configurationClasses.toArray(new String[0]));

      for (String conf : configurationClasses) System.err.println("Enable config class:" + conf);
    }

    // Fix issue 7, File locking on windows/Disable Jetty's locking of
    // static files
    // http://code.google.com/p/run-jetty-run/issues/detail?id=7
    // by disabling the use of the file mapped buffers. The default Jetty
    // behavior is
    // intended to provide a performance boost, but run-jetty-run is focused
    // on
    // development (especially debugging) of web apps, not high-performance
    // production
    // serving of static content. Therefore, I'm not worried about the
    // performance
    // degradation of this change. My only concern is that there might be a
    // need to
    // test this feature that I'm disabling.
    web.setInitParams(
        Collections.singletonMap("org.mortbay.jetty.servlet.Default.useFileMappedBuffer", "false"));

    if (configs.getWebAppClassPath() != null) {
      ProjectClassLoader loader =
          new ProjectClassLoader(web, configs.getWebAppClassPath(), configs.getExcludedclasspath());
      web.setClassLoader(loader);
    }

    List<Resource> resources = new ArrayList<Resource>();

    URL urlWebapp = new File(configs.getWebAppDir()).toURI().toURL();
    Resource webapp = new FileResource(urlWebapp);
    resources.add(webapp);

    Map<String, String> map = configs.getResourceMap();
    for (String key : map.keySet()) {
      /*
      * 			URL url = new File(map.get(key)).toURI().toURL();
      		Resource resource;
      		try {
      			resource = new FileResource(url);
      			final ResourceHandler handler = new ResourceHandler();
      			handler.setBaseResource(resource);
      			handler.setServer(server);
      			handler.setContextPath(key);
      			web.addHandler(handler);
      		} catch (URISyntaxException e) {
      			e.printStackTrace();
      		}

      */
      resources.add(new VirtualResource(webapp, "/" + key, map.get(key)));
      //			final WebAppContext js = new WebAppContext();
      //			js.setContextPath(key);
      //			js.setResourceBase(map.get(key)); // or whatever the correct path is in your case
      //			js.setParentLoaderPriority(true);
      //			server.addHandler(js);
    }

    ResourceCollection webAppDirResources = new ResourceCollection();
    webAppDirResources.setResources(resources.toArray(new Resource[0]));
    web.setBaseResource(webAppDirResources);

    server.addHandler(web);
  }