1.maven的启动方法。在工程的pom。xml文件中加入如下
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<contextPath>/</contextPath>
<scanIntervalSeconds>3</scanIntervalSeconds>
<scanTargetPatterns>
<scanTargetPattern>
<directory>src/main/webapp</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</scanTargetPattern>
</scanTargetPatterns>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8094</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
</plugins>
2.用main方法启动。需要导入jetty的jar包
Server server = new Server();
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setName("Sensei Broker(jetty) threads");
threadPool.setMinThreads(_senseiConf.getInt(SERVER_BROKER_MINTHREAD,20));
threadPool.setMaxThreads(_senseiConf.getInt(SERVER_BROKER_MAXTHREAD,50));
threadPool.setMaxIdleTimeMs(_senseiConf.getInt(SERVER_BROKER_MAXWAIT,2000));
//threadPool.start();
server.setThreadPool(threadPool);
logger.info("request threadpool started.");
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);
server.addConnector(connector);
DefaultSenseiJSONServlet senseiServlet = new DefaultSenseiJSONServlet();
ServletHolder senseiServletHolder = new ServletHolder(senseiServlet);
SenseiHttpInvokerServiceServlet springServlet = new SenseiHttpInvokerServiceServlet();
ServletHolder springServletHolder = new ServletHolder(springServlet);
WebAppContext senseiApp = new WebAppContext();
senseiApp.addFilter(GzipFilter.class,"/sensei/*",1);
//HashMap<String, String> initParam = new HashMap<String, String>();
//if (_senseiConfFile != null) {
//logger.info("Broker Configuration file: "+_senseiConfFile.getAbsolutePath());
//initParam.put("config.file", _senseiConfFile.getAbsolutePath());
//}
//senseiApp.setInitParams(initParam);
senseiApp.setAttribute("sensei.search.configuration", _senseiConf);
senseiApp.setAttribute("sensei.search.version.comparator", _versionComparator);
SenseiLoadBalancerFactory routerFactory = null;
String routerFactoryName = _senseiConf.getString(SERVER_SEARCH_ROUTER_FACTORY, "");
if (routerFactoryName == null || routerFactoryName.equals(""))
routerFactory = new UniformPartitionedRoutingFactory();
else
routerFactory = (SenseiLoadBalancerFactory) _pluginContext.getBean(routerFactoryName);
senseiApp.setAttribute("sensei.search.router.factory", routerFactory);
senseiApp.addEventListener(new SenseiConfigServletContextListener());
senseiApp.addServlet(senseiServletHolder,"/sensei/*");
//senseiApp.addFilter(new FilterHolder(new GzipFilter()), "/sensei/*", 1);
senseiApp.setResourceBase(webappPath);
senseiApp.addServlet(springServletHolder,"/sensei-rpc/SenseiSpringRPCService");
server.setHandler(senseiApp);
server.setStopAtShutdown(true);
server。start()