WAR や XML を必要としない組み込みサーバーを Jetty で実現することは可能です。注釈付きクラスの場所を指定して、追加のクラス パスを追加するだけです。
このメソッドは、名前を付けることができるメインから呼び出す必要がありますServer.java
。
private static void startServer() throws Exception {
final org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(7070);
final WebAppContext context = new WebAppContext("/", "/");
context.setConfigurations(new Configuration[] { new AnnotationConfiguration(), new WebInfConfiguration() });
context.setExtraClasspath("build/classes/main/com/example/servlet");
server.setHandler(context);
server.start();
server.join();
}
私のsrc
構造は次のとおりです。
-main
-java
-com.example
-json
-servlet
-filter
-util
Server.java
Tomcat で同様のソリューションを見たいと思います。