本文整理汇总了Java中org.apache.catalina.Server.stop方法的典型用法代码示例。如果您正苦于以下问题:Java Server.stop方法的具体用法?Java Server.stop怎么用?Java Server.stop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.catalina.Server
的用法示例。
在下文中一共展示了Server.stop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.catalina.Server; //导入方法依赖的package包/类
public static void main(String[] args) {
Connector connector = new Connector();
connector.setPort(80);
Tomcat tomcat = new Tomcat();
tomcat.setPort(80);
tomcat.getService().addConnector(connector);
tomcat.setConnector(connector);
try {
Context ctx = tomcat.addWebapp("", Conf.getAbsolutePath("../src/main/webapp"));
WebResourceRoot resources = new StandardRoot(ctx);
resources.addPreResources(new DirResourceSet(resources,
"/WEB-INF/classes", Conf.getAbsolutePath("classes"), "/"));
ctx.setResources(resources);
Server server = tomcat.getServer();
server.start();
server.setPort(8005);
server.await();
server.stop();
} catch (ServletException | LifecycleException e) {
Log.e(e);
}
}
示例2: stop
import org.apache.catalina.Server; //导入方法依赖的package包/类
/**
* Stop an existing server instance.
*/
public void stop() {
try {
// Remove the ShutdownHook first so that server.stop()
// doesn't get invoked twice
if (useShutdownHook) {
Runtime.getRuntime().removeShutdownHook(shutdownHook);
// If JULI is being used, re-enable JULI's shutdown to ensure
// log messages are not lost
LogManager logManager = LogManager.getLogManager();
if (logManager instanceof ClassLoaderLogManager) {
((ClassLoaderLogManager) logManager).setUseShutdownHook(
true);
}
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
// This will fail on JDK 1.2. Ignoring, as Tomcat can run
// fine without the shutdown hook.
}
// Shut down the server
try {
Server s = getServer();
LifecycleState state = s.getState();
if (LifecycleState.STOPPING_PREP.compareTo(state) <= 0
&& LifecycleState.DESTROYED.compareTo(state) >= 0) {
// Nothing to do. stop() was already called
} else {
s.stop();
s.destroy();
}
} catch (LifecycleException e) {
log.error("Catalina.stop", e);
}
}
示例3: stop
import org.apache.catalina.Server; //导入方法依赖的package包/类
/**
* Stop an existing server instance.
*/
public void stop() {
try {
// Remove the ShutdownHook first so that server.stop()
// doesn't get invoked twice
if (useShutdownHook) {
Runtime.getRuntime().removeShutdownHook(shutdownHook);
// If JULI is being used, re-enable JULI's shutdown to ensure
// log messages are not lost
LogManager logManager = LogManager.getLogManager();
if (logManager instanceof ClassLoaderLogManager) {
((ClassLoaderLogManager) logManager).setUseShutdownHook(true);
}
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
// This will fail on JDK 1.2. Ignoring, as Tomcat can run
// fine without the shutdown hook.
}
// Shut down the server
try {
Server s = getServer();
LifecycleState state = s.getState();
if (LifecycleState.STOPPING_PREP.compareTo(state) <= 0 && LifecycleState.DESTROYED.compareTo(state) >= 0) {
// Nothing to do. stop() was already called
} else {
s.stop();
s.destroy();
}
} catch (LifecycleException e) {
log.error("Catalina.stop", e);
}
}
示例4: main
import org.apache.catalina.Server; //导入方法依赖的package包/类
public static void main(String[] args) {
Connector connector = new Connector();
connector.setPort(80);
Tomcat tomcat = new Tomcat();
tomcat.setPort(80);
tomcat.getService().addConnector(connector);
tomcat.setConnector(connector);
try {
Context ctx = tomcat.addWebapp("", Conf.getAbsolutePath("../src/main/webapp"));
// Ensure to Load All Classes in the Same Class Loader
ctx.setLoader(new WebappLoader(Startup.class.getClassLoader()) {
@Override
public ClassLoader getClassLoader() {
return Startup.class.getClassLoader();
}
});
WebResourceRoot resources = new StandardRoot(ctx);
resources.addPreResources(new DirResourceSet(resources,
"/WEB-INF/classes", Conf.getAbsolutePath("classes"), "/"));
ctx.setResources(resources);
Server server = tomcat.getServer();
server.start();
server.setPort(8005);
server.await();
server.stop();
} catch (ServletException | LifecycleException e) {
Log.e(e);
}
}