我創建了一個eclipse maven項目並添加了jetty依賴項。接下來我做了一個簡單的servlet和一個啓動碼頭服務器的類。這是我到目前爲止:使用web.xml以編程方式啓動jetty
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來配置servlets等。我找不到編程方法來完成其中的一些。我可以創建一個web.xml,並仍然以編程方式啓動我的碼頭,並以某種方式使用該web.xml進行配置?
更具體地說,我需要在web.xml中寫入true。我沒有找到任何方法來編程。
爲什麼不使用maven來完成這項工作? Maven碼頭插件可以用作替代解決方案。 https://www.eclipse.org/jetty/documentation/9.4.x/jetty-maven-plugin.html – artificerpi
嗡嗡聲......對我來說不太清楚。這種編程方式總是與聲明方式不同。你到底想做什麼? –
更具體地說,我需要在web.xml中編寫 true async-supported>。我沒有找到任何方法來編程。 –
user1985273