本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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);
}
示例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");
}
示例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();
}
示例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..完毕");
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}