Spring アプリケーションがあり、Tomcat を使用して開発し、サーバー上で実行しました。deploy->undeploy-->deploy again-->.. 開発プロセスにかなり不満を感じていたので、組み込みの Jetty に切り替えることにしました。したがって、基本的には、サーバーの起動を担当するJavaクラスが1つだけになりました。
public class MainServer {
private Server start() throws Exception {
Server jetty = new Server();
String[] configFiles = { "WebContent/WEB-INF/jetty.xml" };
for (String configFile : configFiles) {
XmlConfiguration configuration = new XmlConfiguration(new File(configFile).toURI().toURL());
configuration.configure(jetty);
}
WebAppContext appContext = new WebAppContext();
File warPath = new File("WebContent");
appContext.setWar(warPath.getAbsolutePath());
appContext.setClassLoader(Thread.currentThread().getContextClassLoader());
appContext.setContextPath("/4d");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { appContext, new DefaultHandler() });
jetty.setHandler(handlers);
jetty.start();
jetty.join();
return jetty;
}
public static void main(String[] args) {
try {
new MainServer().start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
これは、ホットスワップが可能で高速に見えるため、開発に最適です。ただし、後でこの設定をサーバーに展開したいと考えています。このサーバーを起動してバックグラウンドで実行する最良の方法は何ですか (Tomcat startup.sh など)? この MainServer クラスをどのように呼び出す必要がありますか?