私はSpringアプリケーションを開発しており、Tomcatを使ってそれを開発し、サーバ上で実行しています。私はdeploy-> undeploy-> deploy - > ..開発プロセスにかなり不満を抱いていたので、私は組み込みJettyに切り替えることにしました。だから、基本的に今、私は私のサーバーを起動するための責任がちょうど単一のJavaクラスを持っている:それはホットスワップが可能となり、より高速であるように思わとして埋め込みJettyサーバをバックグラウンドプロセスとして起動する
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クラスはどのように呼び出す必要がありますか?
私がやったのは、コードを自分でサーバーを起動することをあきらめ、その代わりに、すべてのパッケージとビルドを処理するようにMavenを設定しました。だから少なくとも今はアプリケーションを実動サーバーに配備するのは面倒ではありません。私は、それについてかなりの話題が既にあるので、後でそのnohupを調べるかもしれない。 – semonte