當前位置: 首頁>>代碼示例>>Java>>正文


Java WebAppContext.setClassLoader方法代碼示例

本文整理匯總了Java中org.eclipse.jetty.webapp.WebAppContext.setClassLoader方法的典型用法代碼示例。如果您正苦於以下問題:Java WebAppContext.setClassLoader方法的具體用法?Java WebAppContext.setClassLoader怎麽用?Java WebAppContext.setClassLoader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jetty.webapp.WebAppContext的用法示例。


在下文中一共展示了WebAppContext.setClassLoader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
public void start() throws Exception
{
    String relativelyPath = System.getProperty("user.dir");

    server = new Server(port);
    WebAppContext webAppContext = new WebAppContext();
    webAppContext.setContextPath("/");
    webAppContext.setWar(relativelyPath + "\\rainbow-web\\target\\rainbow-web.war");
    webAppContext.setParentLoaderPriority(true);
    webAppContext.setServer(server);
    webAppContext.setClassLoader(ClassLoader.getSystemClassLoader());
    webAppContext.getSessionHandler().getSessionManager()
            .setMaxInactiveInterval(10);
    server.setHandler(webAppContext);
    server.start();
}
 
開發者ID:dbiir,項目名稱:rainbow,代碼行數:17,代碼來源:RwServer.java

示例2: createDevServer

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
public static Server createDevServer(int port, String contextPath) {

        Server server = new Server();
        server.setStopAtShutdown(true);

        ServerConnector connector = new ServerConnector(server);
        // 設置服務端口
        connector.setPort(port);
        connector.setReuseAddress(false);
        server.setConnectors(new Connector[] {connector});

        // 設置web資源根路徑以及訪問web的根路徑
        WebAppContext webAppCtx = new WebAppContext(DEFAULT_APP_CONTEXT_PATH, contextPath);
        webAppCtx.setDescriptor(DEFAULT_APP_CONTEXT_PATH + "/WEB-INF/web.xml");
        webAppCtx.setResourceBase(DEFAULT_APP_CONTEXT_PATH);
        webAppCtx.setClassLoader(Thread.currentThread().getContextClassLoader());
        server.setHandler(webAppCtx);

        return server;
    }
 
開發者ID:quqiangsheng,項目名稱:abhot,代碼行數:21,代碼來源:Launcher.java

示例3: configureWebAppContext

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
/**
 * Configure the given Jetty {@link WebAppContext} for use.
 * @param context the context to configure
 * @param initializers the set of initializers to apply
 */
protected final void configureWebAppContext(WebAppContext context,
		ServletContextInitializer... initializers) {
	Assert.notNull(context, "Context must not be null");
	context.setTempDirectory(getTempDirectory());
	if (this.resourceLoader != null) {
		context.setClassLoader(this.resourceLoader.getClassLoader());
	}
	String contextPath = getContextPath();
	context.setContextPath(StringUtils.hasLength(contextPath) ? contextPath : "/");
	context.setDisplayName(getDisplayName());
	configureDocumentRoot(context);
	if (isRegisterDefaultServlet()) {
		addDefaultServlet(context);
	}
	if (shouldRegisterJspServlet()) {
		addJspServlet(context);
		context.addBean(new JasperInitializer(context), true);
	}
	ServletContextInitializer[] initializersToUse = mergeInitializers(initializers);
	Configuration[] configurations = getWebAppContextConfigurations(context,
			initializersToUse);
	context.setConfigurations(configurations);
	configureSession(context);
	postProcessWebAppContext(context);
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:31,代碼來源:JettyEmbeddedServletContainerFactory.java

示例4: createFrontAppContext

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
protected WebAppContext createFrontAppContext(ClassLoader serverClassLoader, ClassLoader sharedClassLoader) throws URISyntaxException {
    ClassLoader frontClassLoader = new URLClassLoader(pathsToURLs(serverClassLoader, getAppClassesPath(FRONT_PATH_IN_JAR)), sharedClassLoader);

    WebAppContext frontContext = new WebAppContext();
    frontContext.setConfigurations(new Configuration[]{new WebXmlConfiguration()});
    frontContext.setContextPath(frontContextPath);
    frontContext.setClassLoader(frontClassLoader);

    setResourceBase(serverClassLoader, frontContext, FRONT_PATH_IN_JAR);

    System.setProperty("cuba.front.baseUrl", PATH_DELIMITER.equals(frontContextPath) ? frontContextPath :
            frontContextPath + PATH_DELIMITER);
    System.setProperty("cuba.front.apiUrl", PATH_DELIMITER.equals(contextPath) ? "/rest/" :
            contextPath + PATH_DELIMITER + "rest" + PATH_DELIMITER);

    return frontContext;
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:18,代碼來源:CubaJettyServer.java

示例5: configureWebAppContext

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
/**
 * Configure the given Jetty {@link WebAppContext} for use.
 * @param context the context to configure
 * @param initializers the set of initializers to apply
 */
protected final void configureWebAppContext(WebAppContext context,
		ServletContextInitializer... initializers) {
	Assert.notNull(context, "Context must not be null");
	context.setTempDirectory(getTempDirectory());
	if (this.resourceLoader != null) {
		context.setClassLoader(this.resourceLoader.getClassLoader());
	}
	String contextPath = getContextPath();
	context.setContextPath(StringUtils.hasLength(contextPath) ? contextPath : "/");
	context.setDisplayName(getDisplayName());
	configureDocumentRoot(context);
	if (isRegisterDefaultServlet()) {
		addDefaultServlet(context);
	}
	if (shouldRegisterJspServlet()) {
		addJspServlet(context);
	}
	ServletContextInitializer[] initializersToUse = mergeInitializers(initializers);
	Configuration[] configurations = getWebAppContextConfigurations(context,
			initializersToUse);
	context.setConfigurations(configurations);
	configureSession(context);
	postProcessWebAppContext(context);
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:30,代碼來源:JettyEmbeddedServletContainerFactory.java

示例6: reloadContext

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
/**
 * 快速重新啟動application,重載target/classes與target/test-classes.
 */
public static void reloadContext(Server server) throws Exception {
	WebAppContext context = (WebAppContext) server.getHandler();

	System.out.println("[INFO] Application reloading");
	context.stop();

	WebAppClassLoader classLoader = new WebAppClassLoader(context);
	classLoader.addClassPath("target/classes");
	classLoader.addClassPath("target/test-classes");
	context.setClassLoader(classLoader);

	context.start();

	System.out.println("[INFO] Application reloaded");
}
 
開發者ID:pengqiuyuan,項目名稱:g2,代碼行數:19,代碼來源:JettyFactory.java

示例7: main

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
 
開發者ID:DistX,項目名稱:Learning,代碼行數:19,代碼來源:EmbeddedServer.java

示例8: reloadContext

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
/**
 * 快速重新啟動Application
 * @see 通常用Main函數啟動JettyServer後,若改動項目的代碼,那就需要停止再啟動Jetty
 * @see 雖免去了Tomcat重新打包幾十兆的消耗,但比起PHP完全不用重啟來說還是慢,特別是關閉,啟動一個新的JVM,消耗不小
 * @see 所以我們可以在Main()中捕捉到回車後調用此函數,即可重新載入應用(包括Spring配置文件)
 * @param server    當前運行的JettyServer實例
 * @param classPath 當前運行的Web應用的classpath
 */
@SuppressWarnings("unused")
private static /*synchronized*/ void reloadContext(Server server, String classPath) throws Exception{
	WebAppContext context = (WebAppContext)server.getHandler();
	System.out.println("Application reloading..開始");
	context.stop();
	WebAppClassLoader classLoader = new WebAppClassLoader(context);
	classLoader.addClassPath(classPath);
	context.setClassLoader(classLoader);
	//根據給定的配置文件初始化日誌配置(否則應用重載後日誌輸出組件就會失效)
	Log4jConfigurer.initLogging(classPath + "/log4j.properties");
	context.start();
	System.out.println("Application reloading..完畢");
}
 
開發者ID:v5java,項目名稱:demo-cas-server-web,代碼行數:22,代碼來源:JettyBootStrap.java

示例9: start

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
public void start() throws Exception
{
    server = new Server(port);

    WebAppContext webAppContext = new WebAppContext();
    webAppContext.setContextPath("/");
    webAppContext.setWar("/Users/Jelly/Developer/paraflow/paraflow-http-server/target/paraflow-server.war");
    webAppContext.setParentLoaderPriority(true);
    webAppContext.setServer(server);
    webAppContext.setClassLoader(ClassLoader.getSystemClassLoader());
    webAppContext.getSessionHandler().getSessionManager()
            .setMaxInactiveInterval(10);
    server.setHandler(webAppContext);
    server.start();
}
 
開發者ID:dbiir,項目名稱:paraflow,代碼行數:16,代碼來源:DataServer.java

示例10: loadWar

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
private WebAppContext loadWar(final File warFile, final String contextPath) throws IOException {
    final WebAppContext webappContext = new WebAppContext(warFile.getPath(), contextPath);
    webappContext.setContextPath(contextPath);
    webappContext.setDisplayName(contextPath);

    // remove slf4j server class to allow WAR files to have slf4j dependencies in WEB-INF/lib
    List<String> serverClasses = new ArrayList<>(Arrays.asList(webappContext.getServerClasses()));
    serverClasses.remove("org.slf4j.");
    webappContext.setServerClasses(serverClasses.toArray(new String[0]));
    webappContext.setDefaultsDescriptor(WEB_DEFAULTS_XML);

    // get the temp directory for this webapp
    final File webWorkingDirectory = properties.getWebWorkingDirectory();
    final File tempDir = new File(webWorkingDirectory, warFile.getName());
    if (tempDir.exists() && !tempDir.isDirectory()) {
        throw new RuntimeException(tempDir.getAbsolutePath() + " is not a directory");
    } else if (!tempDir.exists()) {
        final boolean made = tempDir.mkdirs();
        if (!made) {
            throw new RuntimeException(tempDir.getAbsolutePath() + " could not be created");
        }
    }
    if (!(tempDir.canRead() && tempDir.canWrite())) {
        throw new RuntimeException(tempDir.getAbsolutePath() + " directory does not have read/write privilege");
    }

    // configure the temp dir
    webappContext.setTempDirectory(tempDir);

    // configure the max form size (3x the default)
    webappContext.setMaxFormContentSize(600000);

    webappContext.setClassLoader(new WebAppClassLoader(ClassLoader.getSystemClassLoader(), webappContext));

    logger.info("Loading WAR: " + warFile.getAbsolutePath() + " with context path set to " + contextPath);
    return webappContext;
}
 
開發者ID:apache,項目名稱:nifi-registry,代碼行數:38,代碼來源:JettyServer.java

示例11: loadWar

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
private static WebAppContext loadWar(final File warFile, final String contextPath, final ClassLoader parentClassLoader) throws IOException {
    final WebAppContext webappContext = new WebAppContext(warFile.getPath(), contextPath);
    webappContext.setContextPath(contextPath);
    webappContext.setDisplayName(contextPath);

    // instruction jetty to examine these jars for tlds, web-fragments, etc
    webappContext.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\\\.jar$|.*/[^/]*taglibs.*\\.jar$" );

    // remove slf4j server class to allow WAR files to have slf4j dependencies in WEB-INF/lib
    List<String> serverClasses = new ArrayList<>(Arrays.asList(webappContext.getServerClasses()));
    serverClasses.remove("org.slf4j.");
    webappContext.setServerClasses(serverClasses.toArray(new String[0]));
    webappContext.setDefaultsDescriptor(WEB_DEFAULTS_XML);

    // get the temp directory for this webapp
    File tempDir = Paths.get(C2_SERVER_HOME, "tmp", warFile.getName()).toFile();
    if (tempDir.exists() && !tempDir.isDirectory()) {
        throw new RuntimeException(tempDir.getAbsolutePath() + " is not a directory");
    } else if (!tempDir.exists()) {
        final boolean made = tempDir.mkdirs();
        if (!made) {
            throw new RuntimeException(tempDir.getAbsolutePath() + " could not be created");
        }
    }
    if (!(tempDir.canRead() && tempDir.canWrite())) {
        throw new RuntimeException(tempDir.getAbsolutePath() + " directory does not have read/write privilege");
    }

    // configure the temp dir
    webappContext.setTempDirectory(tempDir);

    // configure the max form size (3x the default)
    webappContext.setMaxFormContentSize(600000);

    webappContext.setClassLoader(new WebAppClassLoader(parentClassLoader, webappContext));

    logger.info("Loading WAR: " + warFile.getAbsolutePath() + " with context path set to " + contextPath);
    return webappContext;
}
 
開發者ID:apache,項目名稱:nifi-minifi,代碼行數:40,代碼來源:JettyServer.java

示例12: createAppContext

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
protected WebAppContext createAppContext(ClassLoader serverClassLoader, ClassLoader sharedClassLoader,
                                         String appPathInJar, String contextPath) throws URISyntaxException {
    ClassLoader appClassLoader = new URLClassLoader(pathsToURLs(serverClassLoader, getAppClassesPath(appPathInJar)), sharedClassLoader);

    WebAppContext appContext = new WebAppContext();
    appContext.setConfigurations(new Configuration[]{new WebXmlConfiguration(), createEnvConfiguration()});
    appContext.setContextPath(contextPath);
    appContext.setClassLoader(appClassLoader);

    setResourceBase(serverClassLoader, appContext, appPathInJar);

    return appContext;
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:14,代碼來源:CubaJettyServer.java

示例13: start

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
public void start(boolean devMode, int port) throws Exception {

        Server server = new Server(new QueuedThreadPool(500));

        WebAppContext appContext = new WebAppContext();

        String resourceBasePath = "";
        //開發者模式
        if (devMode) {
            String artifact = MavenUtils.get(Thread.currentThread().getContextClassLoader()).getArtifactId();
            resourceBasePath = artifact + "/src/main/webapp";
        }
        appContext.setDescriptor(resourceBasePath + "WEB-INF/web.xml");
        appContext.setResourceBase(resourceBasePath);
        appContext.setExtractWAR(true);

        //init param
        appContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
        if (CommonUtils.isWindowOs()) {
            appContext.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
        }

        //for jsp support
        appContext.addBean(new JettyJspParser(appContext));
        appContext.addServlet(JettyJspServlet.class, "*.jsp");

        appContext.setContextPath("/");
        appContext.getServletContext().setExtendedListenerTypes(true);
        appContext.setParentLoaderPriority(true);
        appContext.setThrowUnavailableOnStartupException(true);
        appContext.setConfigurationDiscovered(true);
        appContext.setClassLoader(Thread.currentThread().getContextClassLoader());

        ServerConnector connector = new ServerConnector(server);
        connector.setHost("0.0.0.0");
        connector.setPort(port);
        server.setConnectors(new Connector[]{connector});
        server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", 1024 * 1024 * 1024);
        server.setDumpAfterStart(false);
        server.setDumpBeforeStop(false);
        server.setStopAtShutdown(true);
        server.setHandler(appContext);
        logger.info("[opencron] JettyLauncher starting...");
        server.start();
    }
 
開發者ID:wolfboys,項目名稱:opencron,代碼行數:46,代碼來源:JettyLauncher.java

示例14: startJettyServer

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
private static void startJettyServer() throws Exception {

		final Server server = new Server(Configs.getInt("jetty.port"));
		
		WebAppContext context = new WebAppContext();
		String classesPath = RexxarReaderWebBoot.class.getProtectionDomain().getCodeSource().getLocation().toExternalForm();
		String webContextPath = StringUtils.substringBefore(classesPath, "/WEB-INF");
		logger.info("classesPath : {}",classesPath);
		logger.info("web context : {}",webContextPath);
		
		context.setResourceBase(webContextPath);
		context.setContextPath("/");
		context.setParentLoaderPriority(true);
		context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
		context.setClassLoader(Thread.currentThread().getContextClassLoader());
	    context.setConfigurationClasses(Lists.newArrayList("org.eclipse.jetty.webapp.WebInfConfiguration",
	            "org.eclipse.jetty.webapp.WebXmlConfiguration",
	            "org.eclipse.jetty.webapp.MetaInfConfiguration",
	            "org.eclipse.jetty.webapp.FragmentConfiguration",
	            "org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
	            "org.eclipse.jetty.annotations.AnnotationConfiguration"));
	   
	    server.setHandler(context);

	    server.start();		
	    
	    logger.info("reader server start");
	    
	    Runtime.getRuntime().addShutdownHook(new Thread() {
	        @Override
	        public void run() {
	          try {
	            server.stop();
	            logger.info("reader server stop");
	          } catch (Exception e) {
	            logger.error(e.getMessage(),e);
	            e.printStackTrace();
	          }
	        }
	      });
	      
	    server.join();
	    
	}
 
開發者ID:phoenix2014,項目名稱:rexxar,代碼行數:45,代碼來源:RexxarReaderWebBoot.java

示例15: build

import org.eclipse.jetty.webapp.WebAppContext; //導入方法依賴的package包/類
/**
 * 創建用於正常運行調試的Jetty Server, 以src/main/webapp為Web應用目錄.
 */
@Override
public Server build(int port, String webApp, String contextPath) throws BindException {
	port = this.getAutoPort(port);

	serverInitializer.run();

	Server server = new Server(port);
	WebAppContext webContext = new WebAppContext(webApp, contextPath);

	if (false) {
		ServletHolder holder = new ServletHolder(new ProxyServlet());
		holder.setInitParameter("proxyTo", "http://localhost:3000/");
		holder.setInitParameter("prefix", "/");

		webContext.addServlet(holder, "/app/");
		webContext.addServlet(new ServletHolder(new IndexServlet()), "/proxy/");
	}

	// webContext.setDefaultsDescriptor("leopard-jetty/webdefault.xml");

	// 問題點:http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration

	webContext.setConfigurations(new Configuration[] { //
			new EmbedWebInfConfiguration(), //
			new MetaInfConfiguration(), //
			new AnnotationConfiguration(), //
			new WebXmlConfiguration(), //
			new FragmentConfiguration() //
			// new TagLibConfiguration() //
	});

	// webContext.setConfigurations(new Configuration[] { //
	// new EmbedWebInfConfiguration()//
	// , new EmbedWebXmlConfiguration()//
	// , new EmbedMetaInfConfiguration()//
	// , new EmbedFragmentConfiguration()//
	// , new EmbedAnnotionConfiguration() //
	// // , new PlusConfiguration(),//
	// // new EnvConfiguration()//
	// });

	WebAppClassLoader classLoader = null;
	try {
		// addTldLib(webContext);
		classLoader = new LeopardWebAppClassLoader(webContext);
	}
	catch (IOException e) {
		e.printStackTrace();
	}
	// ClassLoader tldClassLoader = addTldLib(classLoader);
	webContext.setClassLoader(classLoader);

	webContext.setParentLoaderPriority(true);
	// logger.debug(webContext.dump());

	Handler rewriteHandler = ResourcesManager.getHandler();
	if (rewriteHandler == null) {
		server.setHandler(webContext);
	}
	else {
		HandlerCollection handlers = new HandlerCollection();
		handlers.addHandler(rewriteHandler);
		handlers.addHandler(webContext);
		server.setHandler(handlers);
	}
	server.setStopAtShutdown(true);

	return server;
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:73,代碼來源:WebServerJettyImpl.java


注:本文中的org.eclipse.jetty.webapp.WebAppContext.setClassLoader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。