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

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

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

WebAppContext.setContextPath介绍

暂无

代码示例

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

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;

public class JettyServer {
 public static void main(String[] args) {
 Server server = new Server(8080);

 WebAppContext context = new WebAppContext();
 context.setResourceBase("../webapp-project/WebContent");
 context.setDescriptor("../webapp-project/WebContent/WEB-INF/web.xml");
 context.setContextPath("/");
 context.setParentLoaderPriority(true);
 server.setHandler(context);

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

代码示例来源:origin: ocpsoft/prettytime

public static void main(String[] args) throws Exception {
  String weppAppHome = args[0];
  Integer port = 8080;
  Server server = new Server(port);
  WebAppContext webapp = new WebAppContext();
  webapp.setContextPath("/");
  webapp.setCompactPath(true);
  webapp.setDescriptor(weppAppHome + "/WEB-INF/web.xml");
  webapp.setResourceBase(weppAppHome);
  webapp.setParentLoaderPriority(true);
  server.setHandler(webapp);
  server.start();
  server.join();
}

代码示例来源:origin: kaaproject/kaa

@Override
public void start() {
 LOG.info("Starting Kaa Admin Web Server...");
 server = new Server(adminPort);
 webAppContext = new WebAppContext();
 webAppContext.setEventListeners(new EventListener[]{adminContextLoaderListener});
 webAppContext.setContextPath("/");
 String webXmlLocation = AdminInitializationService.class.getResource("/admin-web/WEB-INF/"
   + webXmlFile).toString();
 webAppContext.setDescriptor(webXmlLocation);
 String resLocation = AdminInitializationService.class.getResource("/admin-web").toString();
 webAppContext.setResourceBase(resLocation);
 webAppContext.setParentLoaderPriority(true);
 server.setHandler(webAppContext);
 try {
  server.start();
  LOG.info("Kaa Admin Web Server started.");
 } catch (Exception ex) {
  LOG.error("Error starting Kaa Admin Web Server!", ex);
 }
}

代码示例来源:origin: Netflix/eureka

private static void startServer() throws Exception {
  File warFile = findWar();
  server = new Server(8080);
  WebAppContext webapp = new WebAppContext();
  webapp.setContextPath("/");
  webapp.setWar(warFile.getAbsolutePath());
  server.setHandler(webapp);
  server.start();
  eurekaServiceUrl = "http://localhost:8080/v2";
}

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

/**
 * Create the web context for the application of specified name
 */
WebAppContext createWebAppContext(Builder b) {
 WebAppContext ctx = new WebAppContext();
 setContextAttributes(ctx.getServletContext(), b.contextAttrs);
 ctx.setDisplayName(b.name);
 ctx.setContextPath("/");
 ctx.setWar(appDir + "/" + b.name);
 return ctx;
}

代码示例来源: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: jersey/jersey

WebAppContext context = new WebAppContext();
context.setDisplayName("JettyContext");
context.setContextPath(path);
context.setConfigurations(new Configuration[]{new WebXmlConfiguration()});
ServletHolder holder;

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

server.setConnectors(new Connector[] { connector });
WebAppContext bb = new WebAppContext();
bb.setServer(server);
bb.setContextPath("/");
bb.setWar("src/main/webapp");

代码示例来源:origin: Dreampie/Resty

webAppContext = new WebAppContext();
webXmlPath = webappUrl + "/WEB-INF/web.xml";
webAppContext.setDescriptor(webXmlPath);
webAppContext.setContextPath(contextPath);
webAppContext.setResourceBase(webappUrl);

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

WebAppContext webapp = new WebAppContext();
webapp.setContextPath(webAppContext);
webapp.setWar(warFilePath);
webapp.setParentLoaderPriority(false);

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

private WebAppContext loadWar(final File warFile, final String contextPath, final ClassLoader parentClassLoader) {
  final WebAppContext webappContext = new WebAppContext(warFile.getPath(), contextPath);
  webappContext.setContextPath(contextPath);
  webappContext.setDisplayName(contextPath);

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

private WebAppContext createWebAppContext() {
  webAppContext = new WebAppContext();
  webAppContext.setDefaultsDescriptor(GoWebXmlConfiguration.configuration(getWarFile()));
  webAppContext.setConfigurationClasses(new String[]{
      WebInfConfiguration.class.getCanonicalName(),
      WebXmlConfiguration.class.getCanonicalName(),
      JettyWebXmlConfiguration.class.getCanonicalName()
  });
  webAppContext.setContextPath(systemEnvironment.getWebappContextPath());
  // delegate all logging to parent classloader to avoid initialization of loggers in multiple classloaders
  webAppContext.addSystemClass("org.apache.log4j.");
  webAppContext.addSystemClass("org.slf4j.");
  webAppContext.addSystemClass("org.apache.commons.logging.");
  webAppContext.setWar(getWarFile());
  webAppContext.setParentLoaderPriority(systemEnvironment.getParentLoaderPriority());
  return webAppContext;
}

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

Server server = new Server();
 // Note: if you don't want control over type of connector, etc. you can simply 
 // call new Server(<port>);
 ServerConnector connector = new ServerConnector(server);
 connector.setHost("0.0.0.0");
 connector.setPort(8085);
 // Setting the name allows you to serve different app contexts from different connectors.
 connector.setName("main");
 server.addConnector(connector);
 WebAppContext context = new WebAppContext();
 context.setContextPath("/");
 // For development within an IDE like Eclipse, you can directly point to the web.xml
 context.setWar("src/main/webapp");
 context.addFilter(MyFilter.class, "/", 1);
 HandlerCollection collection = new HandlerCollection();
 RequestLogHandler rlh = new RequestLogHandler();
 // Slf4j - who uses anything else?
 Slf4jRequestLog requestLog = new Slf4jRequestLog();
 requestLog.setExtended(false);
 rlh.setRequestLog(requestLog);
 collection.setHandlers(new Handler[] { context, rlh });
 server.setHandler(collection);
 try {
   server.start();
   server.join();
 } catch (Exception e) {
   // Google guava way
   throw Throwables.propagate(e);
 }

代码示例来源:origin: DeemOpen/zkui

Server server = new Server();
WebAppContext servletContextHandler = new WebAppContext();
servletContextHandler.setContextPath("/");
servletContextHandler.setResourceBase("src/main/resources/" + webFolder);
ClassList clist = ClassList.setServerDefault(server);

代码示例来源:origin: org.apache.hadoop/hadoop-common

private static WebAppContext createWebAppContext(Builder b,
  AccessControlList adminsAcl, final String appDir) {
 WebAppContext ctx = new WebAppContext();
 ctx.setDefaultsDescriptor(null);
 ServletHolder holder = new ServletHolder(new DefaultServlet());
 Map<String, String> params = ImmutableMap. <String, String> builder()
     .put("acceptRanges", "true")
     .put("dirAllowed", "false")
     .put("gzip", "true")
     .put("useFileMappedBuffer", "true")
     .build();
 holder.setInitParameters(params);
 ctx.setWelcomeFiles(new String[] {"index.html"});
 ctx.addServlet(holder, "/");
 ctx.setDisplayName(b.name);
 ctx.setContextPath("/");
 ctx.setWar(appDir + "/" + b.name);
 String tempDirectory = b.conf.get(HTTP_TEMP_DIR_KEY);
 if (tempDirectory != null && !tempDirectory.isEmpty()) {
  ctx.setTempDirectory(new File(tempDirectory));
  ctx.setAttribute("javax.servlet.context.tempdir", tempDirectory);
 }
 ctx.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, b.conf);
 ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl);
 addNoCacheFilter(ctx);
 return ctx;
}

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

final WebAppContext staticContext = new WebAppContext();
staticContext.setServer( getJetty() );
staticContext.setContextPath( mountPoint );
staticContext.setSessionHandler( sessionHandler );
staticContext.setInitParameter( "org.eclipse.jetty.servlet.Default.dirAllowed", "false" );

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

private static WebAppContext createWebAppContext(String name,
  Configuration conf, AccessControlList adminsAcl, final String appDir) {
 WebAppContext ctx = new WebAppContext();
 ctx.setDisplayName(name);
 ctx.setContextPath("/");
 ctx.setWar(appDir + "/" + name);
 ctx.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, conf);
 // for org.apache.hadoop.metrics.MetricsServlet
 ctx.getServletContext().setAttribute(
  org.apache.hadoop.http.HttpServer2.CONF_CONTEXT_ATTRIBUTE, conf);
 ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl);
 addNoCacheFilter(ctx);
 return ctx;
}

代码示例来源:origin: yahoo/mysql_perf_analyzer

private WebAppContext createDeployedApplicationInstance(File workDirectory,
    String deployedApplicationPath) {
  WebAppContext deployedApplication = new WebAppContext();
  deployedApplication.setContextPath(this.getContextPath());
  deployedApplication.setWar(deployedApplicationPath);
  deployedApplication.setAttribute("javax.servlet.context.tempdir",
      workDirectory.getAbsolutePath());
  deployedApplication
      .setAttribute(
          "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
          ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/.*taglibs.*\\.jar$");
  deployedApplication.setAttribute(
      "org.eclipse.jetty.containerInitializers", jspInitializers());
  deployedApplication.setAttribute(InstanceManager.class.getName(),
      new SimpleInstanceManager());
  deployedApplication.addBean(new ServletContainerInitializersStarter(
      deployedApplication), true);
  // webapp.setClassLoader(new URLClassLoader(new
  // URL[0],App.class.getClassLoader()));
  deployedApplication.addServlet(jspServletHolder(), "*.jsp");
  return deployedApplication;
}

代码示例来源:origin: loklak/loklak_server

WebAppContext htrootContext = new WebAppContext();
htrootContext.setContextPath("/");

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

Server server.setConnectors(new Connector[] { socketConnector });
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/"); // For root
webapp.setWar("/"); // Appropriate file system path.

相关文章

WebAppContext类方法