org.eclipse.jetty.webapp.WebAppContext.setServer()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中org.eclipse.jetty.webapp.WebAppContext.setServer()方法的一些代码示例,展示了WebAppContext.setServer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebAppContext.setServer()方法的具体详情如下:
包路径:org.eclipse.jetty.webapp.WebAppContext
类名称:WebAppContext
方法名:setServer

WebAppContext.setServer介绍

[英]Set the server classes patterns.

Server classes/packages are classes used to implement the server and are hidden from the context. If the context needs to load these classes, it must have its own copy of them in WEB-INF/lib or WEB-INF/classes. A ClasspathPattern is used to match the server classes.
[中]设置服务器类模式。
服务器类/包是用于实现服务器的类,对上下文隐藏。如果上下文需要加载这些类,它必须在WEB-INF/lib或WEB-INF/classes中有自己的副本。ClasspathPattern用于匹配服务器类。

代码示例

代码示例来源:origin: json-path/JsonPath

public static void main(String[] args) throws Exception {
  String configPort = "8080";
  if(args.length > 0){
    configPort = args[0];
  }
  String port = System.getProperty("server.http.port", configPort);
  System.out.println("Server started on port: " + port);
  Server server = new Server();
  server.setConnectors(new Connector[]{createConnector(server, Integer.parseInt(port))});
  ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
  context.setContextPath("/api");
  ServletHolder servletHolder = new ServletHolder(createJerseyServlet());
  servletHolder.setInitOrder(1);
  context.addServlet(servletHolder, "/*");
  WebAppContext webAppContext = new WebAppContext();
  webAppContext.setServer(server);
  webAppContext.setContextPath("/");
  String resourceBase = System.getProperty("resourceBase");
  if(resourceBase != null){
    webAppContext.setResourceBase(resourceBase);
  } else {
    webAppContext.setResourceBase(Main.class.getResource("/webapp").toExternalForm());
  }
  HandlerList handlers = new HandlerList();
  handlers.setHandlers(new Handler[]{context, webAppContext});
  server.setHandler(handlers);
  server.start();
  server.join();
}

代码示例来源:origin: apache/hbase

final WebAppContext context = new WebAppContext(null, "/", null, null, null, null, WebAppContext.NO_SESSIONS);
context.addServlet(new ServletHolder(redirect), "/*");
context.setServer(masterJettyServer);

代码示例来源:origin: stackoverflow.com

bb.setServer(server);
bb.setContextPath("/");
bb.setWar("src/main/webapp");

代码示例来源:origin: neo4j/neo4j

sessionHandler.setServer( getJetty() );
final WebAppContext staticContext = new WebAppContext();
staticContext.setServer( getJetty() );
staticContext.setContextPath( mountPoint );
staticContext.setSessionHandler( sessionHandler );

代码示例来源:origin: apache/shiro

ctx.setServer(server);

代码示例来源:origin: stackoverflow.com

Server server = new Server();
ServerConnector http = new ServerConnector(server);
http.setPort(8080);
server.addConnector(http);

WebAppContext bb = new WebAppContext();
bb.setServer(server);
bb.setContextPath("/");
bb.setWar("src/main/webapp");

server.setHandler(bb);

try
{
  server.start();
  server.join();
}
catch (Exception e)
{
  e.printStackTrace();
  System.exit(100);
}

代码示例来源:origin: stackoverflow.com

server = new Server();
 SocketConnector connector = new SocketConnector();
 connector.setPort(8080);
 server.setConnectors(new Connector[] { connector });
 WebAppContext context = new WebAppContext();
 context.setServer(server);
 context.setContextPath("/your-context");
 context.setWar("path to war");
 server.addHandler(context);
 Thread monitor = new MonitorThread();
 monitor.start();
 server.start();
 server.join();

代码示例来源:origin: stackoverflow.com

final Server server = new Server();
//skipped socketconnector initialization

final WebAppContext js = new WebAppContext();
js.setServer(server);
js.setContextPath("/js");
js.setWar("target/classes/js"); // or whatever the correct path is in your case
server.addHandler(js);

// css the same way

final WebAppContext bb = new WebAppContext();
bb.setServer(server);
bb.setContextPath("/");
bb.setWar("src/main/webapp");
server.addHandler(bb);

server.start();

代码示例来源:origin: stackoverflow.com

final Connector connector = new SelectChannelConnector();
 connector.setPort(8080);
 final Server server = new Server();
 server.addConnector(connector);
 server.setStopAtShutdown(true);
 final WebAppContext context = new WebAppContext();
 context.setContextPath("/");
 context.setServer(server);
 final ProtectionDomain protectionDomain = Main.class.getProtectionDomain();
 final URL location = protectionDomain.getCodeSource().getLocation();
 context.setWar(location.toExternalForm());
 server.addHandler(context);
 server.start();
 server.join();

代码示例来源:origin: stackoverflow.com

final Server server = new Server();
//skipped socketconnector initialization

final WebAppContext bb = new WebAppContext();
bb.setServer(server);
bb.setContextPath("/");
bb.setWar("src/main/webapp");
final URL url = new File("target/classes").getAbsoluteFile().toURI().toURL();
final Resource resource = new FileResource(url);
final ResourceHandler handler = new ResourceHandler();
handler.setBaseResource(resource);
server.addHandler(handler);
server.addHandler(bb);
server.start();

代码示例来源:origin: stackoverflow.com

webAppContext.setServer(server);
server.setHandler(webAppContext);

代码示例来源:origin: stackoverflow.com

context.setServer(server);
context.setContextPath("/");
context.setWar("src/main/webapp");

代码示例来源:origin: de.alpharogroup/jetty-runner-core

/**
 * Gets the web app context.
 *
 * @param server
 *            the server
 * @param projectname
 *            the projectname
 * @return the web app context
 */
public static WebAppContext getWebAppContext(final Server server, final String projectname)
{
  final File webapp = PathFinder.getProjectDirectory();
  final File wa = PathFinder.getRelativePath(webapp, projectname, "src", "main", "webapp");
  final WebAppContext webAppContext = new WebAppContext();
  webAppContext.setServer(server);
  webAppContext.setContextPath("/");
  webAppContext.setWar(wa.getAbsolutePath());
  return webAppContext;
}

代码示例来源:origin: de.saumya.mojo/jruby-mains

context.setServer(server);
context.setContextPath("/");
context.setExtractWAR(false);

代码示例来源:origin: org.jruby.mains/jruby-mains

context.setServer(server);
context.setContextPath("/");
context.setExtractWAR(false);

代码示例来源:origin: org.apache.activemq/activemq-optional

public static void main(String[] args) throws Exception {
    Server server = new Server();
    Connector context = new SocketConnector();
    context.setServer(server);
    context.setPort(PORT);

    String webappDir = WEBAPP_DIR;
    if (args.length > 0) {
      webappDir = args[0];
    }

    WebAppContext webapp = new WebAppContext();
    webapp.setServer(server);
    webapp.setContextPath(WEBAPP_CTX);
    webapp.setResourceBase(webappDir);

    server.setHandler(webapp);

    server.setConnectors(new Connector[] {
      context
    });
    server.start();

  }
}

代码示例来源:origin: zenvisage/zenvisage

public void start() throws Exception {	
    server = new Server(port);	
    
    WebAppContext webAppContext = new WebAppContext();
    webAppContext.setContextPath("/");
    webAppContext.setWar("zenvisage.war");
    webAppContext.setParentLoaderPriority(true);
    webAppContext.setServer(server);
    webAppContext.setClassLoader(ClassLoader.getSystemClassLoader());
    webAppContext.getSessionHandler().getSessionManager()
        .setMaxInactiveInterval(10);
    server.setHandler(webAppContext);    
    server.start();
//        ZvMain zvMain = (ZvMain) SpringApplicationContext.getBean("zvMain");
//        zvMain.loadData();
    
    DatabaseAutoLoader databaseAutoLoader = new DatabaseAutoLoader(this);
    databaseAutoLoader.run();
  
  }

代码示例来源:origin: com.github.jruby-gradle/jruby-gradle-plugin

public String addRepository(String url) {
  if (urls.contains(url)) {
    return null;
  }
  String path = "/" + url.replace("://", "_")
              .replace(":", "_")
              .replace("/", "_")
              .replace(".", "_");
  WebAppContext context = new WebAppContext();
  context.setServer(server);
  context.setContextPath(path);
  context.setExtractWAR(false);
  context.setCopyWebInf(true);
  context.setWar(rubygemsWarURI);
  context.setInitParameter("gem-caching-proxy-url", url);
  context.setInitParameter("gem-caching-proxy-storage",
               new File(cachedir, path).getAbsolutePath());
  // do not setup other repos
  context.setInitParameter("gem-proxy-storage", "");
  context.setInitParameter("gem-hosted-storage", "");
  context.setInitParameter("gem-merged", "false");
  this.handlerCollection.addHandler(context);
  return path + "/caching/maven/releases";
}

代码示例来源:origin: org.leapframework/leap-webunit

public TWebServer duplicateContext(String existsContextPath,String duplicateContextPath) throws IllegalStateException{
  WebAppContext context = contexts.get(existsContextPath);
  
  if(null == context){
    throw new IllegalStateException("The given argument [existsContextPath] '" + existsContextPath + "' not exists");
  }
  
  if(contexts.containsKey(duplicateContextPath)){
    throw new IllegalStateException("The given argument [duplicateContextPath] '" + duplicateContextPath + "' aleady exists");
  }
  
  WebAppContext duplicateContext = new WebAppContext();
  duplicateContext.setContextPath(duplicateContextPath);
  duplicateContext.setClassLoader(context.getClassLoader());
  duplicateContext.setParentLoaderPriority(context.isParentLoaderPriority());
  duplicateContext.setServer(server);
  duplicateContext.setErrorHandler(context.getErrorHandler());
  duplicateContext.setBaseResource(context.getBaseResource());
  duplicateContext.setThrowUnavailableOnStartupException(context.isThrowUnavailableOnStartupException());
  contexts.put(duplicateContextPath, duplicateContext);
  
  return this;
}

代码示例来源:origin: stackoverflow.com

private static ContextHandlerCollection prepareContexts() {

  MovedContextHandler handler = new MovedContextHandler();
  handler.setContextPath("/membership");
  handler.setNewContextURL("/#/membership");
  handler.setPermanent(true);
  handler.setDiscardPathInfo(false);
  handler.setDiscardQuery(false);

  WebAppContext webAppContext = new WebAppContext();
  webAppContext.setServer(server);
  webAppContext.setContextPath("/");
  webAppContext.setWar("src/main/webapp");

  ContextHandlerCollection contexts = new ContextHandlerCollection();
  contexts.setHandlers(new Handler[] { handler, webAppContext });

  return contexts;
}

相关文章

WebAppContext类方法