LoginSignup
2
2

More than 5 years have passed since last update.

Embedded Tomcatの設定用のコードを読んでみた

Posted at

Embedding Tomcat 7 | Coppery Keen Clawsを読んでみたが、
Tomcatがまだよく分かってないこともあり各行が何をしているか分からなかった
ので調べてみた。

public static void main(String[] args) throws Exception {
  String appBase = args[0];
  Integer port = Integer.valueOf(args[1]);

  Tomcat tomcat = new Tomcat();    // Tomcatインスタンス生成
  tomcat.setPort(port);    // Tomcatにアクセスするポート番号を指定

  tomcat.setBaseDir(".");    // tempファイルを配置するためのディレクトリとして、指定が必要。最初に呼ばれるメソッドであるべき、とかかれている。設定されない場合各自のシステム設定に依存する。
  tomcat.getHost().setAppBase(appBase);    // TomcatインスタンスのAppBaseを設定する。AppBaseとは起動するTomcatインスタンスのベースディレクトリ。指定されないと$CATALINA_BASE/webappsが指定される。

  String contextPath = "/myapp";

  // Add AprLifecycleListener    // APR = Apache Portable Runtime
  StandardServer server = (StandardServer)tomcat.getServer();    // JVMのServerインスタンスを取得する。
  AprLifecycleListener listener = new AprLifecycleListener();
  server.addLifecycleListener(listener);    // ライフサイクルリスナーを指定

  tomcat.addWebapp(contextPath, appBase);    // Tomcatインスタンスにwebappを追加する。$CATALINA_HOME/webapps配下にアプリケーションを配置するのと同じ。 $CATALINA_HOME/webapps/appBase/contextPathにアプリが配置され
るイメージ多分)
  tomcat.start();    // Tomcat起動
  tomcat.getServer().await();    //    awaitで、正常なシャットダウンコマンドが送られてくるまで待機する。
}

現在進行形で勉強中なので、これからも分かったことは追記するつもりです。
特に参考資料は自分のためにもここにまとめておきたいです。

参考資料

Embedded Tomcat起動の設定方法系

JSPが読み込まれない系

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2