【发布时间】:2017-02-24 00:34:18
【问题描述】:
我创建了一个 eclipse maven 项目并添加了 jetty 依赖项。接下来我制作了一个简单的 servlet 和一个启动码头服务器的类。这是我到目前为止得到的:
package com.example.jetty;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
public class App {
public static void main(String[] args) throws Exception {
Server server = new Server(80);
ServletContextHandler servletContext = new ServletContextHandler(server, "/");
servletContext.addServlet(MyServlet.class, "/");
server.start();
}
}
我的问题是我看到的大多数教程都有一个 web.xml 来配置 servlet 等。我找不到执行其中一些的程序化方法。我可以创建一个 web.xml 并仍然以编程方式启动我的码头并以某种方式使用该 web.xml 进行配置吗?
更具体地说,我需要在 web.xml 中写入 true。我没有找到任何以编程方式执行此操作的方法。
【问题讨论】:
-
为什么不直接使用 maven 来完成这项工作呢? Maven jetty-plugin 可以用作替代解决方案。 eclipse.org/jetty/documentation/9.4.x/jetty-maven-plugin.html
-
嗯...我不太清楚。编程方式总是不同于声明方式。你到底想做什么?
-
更具体地说,我需要在 web.xml 中编写
true 。我没有找到任何以编程方式执行此操作的方法。