package runtime;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;
public class JettyStarter {
public static void main(String[] args) throws Exception {
long begin = System.currentTimeMillis();
Connector connector = new SelectChannelConnector();
connector.setPort(Integer.getInteger("jetty.port", 8000).intValue());
WebAppContext webapp = new WebAppContext("WebRoot","/struts2-blank");
Server server = new Server();
server.setConnectors(new Connector[] { connector });
server.setHandler(webapp);
server.start();
System.out.println("Jetty Server started, use " + (System.currentTimeMillis() - begin) + " ms");
}
}
注意:直接http://localhost:8000/ 是报404 错误的,因为这是嵌入式的jetty,没有默认的程序
需要带上应用名称:http://localhost:8000/struts2-blank
本文详细介绍了如何使用 Jetty 运行时环境启动 Web 应用,并提供了实例代码和注意事项,帮助开发者理解 Jetty 的基本配置和使用。
2687

被折叠的 条评论
为什么被折叠?



