java 以编程方式启动 Jetty 9
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17124754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Launch Jetty 9 Programmatically
提问by Fernando Aspiazu
Does someone know how to launch Jetty9 with a simple main in Java class??? For example, I've seen programs like:
有人知道如何在 Java 类中使用简单的 main 启动 Jetty9 吗???例如,我见过这样的程序:
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
WebAppContext webAppContext = new WebAppContext("./src/main/webapp", "/recruiting");
webAppContext.setLogUrlOnStart(true);
webAppContext.setInitParameter(ContextLoader.CONTEXT_CLASS_PARAM, RecruitingAppContext.class.getName());
webAppContext.addServlet(DispatcherServlet.class, "/");
webAppContext.setWelcomeFiles(new String[]{"index.jsp"});
webAppContext.addEventListener(new RequestContextListener());
webAppContext.configure();
server.setHandler(webAppContext);
server.start();
System.out.println("Server started");
server.join();
}
But I'm not yet able to run Jetty9 successfully. Anyway, I'm trying to do this with spring. Do someone let me see some examples in order to do this??? Thanks a lot :-)
但是我还不能成功运行 Jetty9。无论如何,我正在尝试用春天来做到这一点。有人让我看一些例子来做到这一点吗???非常感谢 :-)
回答by jesse mcconnell
I just documented one of our examples here a couple weeks back. We'll be documenting more of our examples and adding some as we get requests and as folks submit their own...
几周前,我刚刚在这里记录了我们的一个示例。我们将记录更多示例,并在收到请求和人们提交自己的请求时添加一些示例...
anyway, this ought to get you going :)
无论如何,这应该能让你继续前进:)
http://www.eclipse.org/jetty/documentation/current/embedded-examples.html#embedded-one-webapp
http://www.eclipse.org/jetty/documentation/current/embedded-examples.html#embedded-one-webapp