package com.chinasunzone.jetty;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;
import org.mortbay.thread.BoundedThreadPool;
/**
* 使用jetty来启动web服务的一个例子
*
* @author cong_px
* @date 2008/10/18
*/
public class JettyServer {
@Deprecated
public static void main(String[] args) throws Exception {
// Jetty HTTP Servlet Server.
Server server = new Server();
BoundedThreadPool threadPool = new BoundedThreadPool();
// 设置线程池
threadPool.setMaxThreads(100);
server.setThreadPool(threadPool);
// 设置连接参数
Connector connector = new SelectChannelConnector();
// 设置监听端口
connector.setPort(8000);
// 为服务设置连接器
server.setConnectors(new Connector[] { connector });
WebAppContext context = new WebAppContext();
// 设置contextPath如:http://localhost:8000/test...
context.setContextPath("/test");
// 启动的war包的位置
context.setWar("F:/Jetty/jetty-6.1.11/jetty-6.1.11/webapps/cometd.war");
server.addHandler(context);
server.setStopAtShutdown(true);
server.setSendServerVersion(true);
server.start();
// 将服务添加到连接池中
server.join();
}
}
使用jetty来启动一个web服务
最新推荐文章于 2021-01-12 18:23:29 发布