Maven2でtomcat-maven-pluginを使う
Tomcatでウェブアプリケーションをデプロイするのに便利なプラグイン。
maven1のときも使ってたんですが、maven2のはまだ試してなかったのでメモ。
tomcatのデフォルトのユーザではなくて別のユーザーでデプロイしたいとか、パスワードが空白じゃないときは、まずsettings.xmlに以下のように記述*1。
<?xml version="1.0" encoding="UTF-8"?> <settings> <servers> <server> <id>local_tomcat</id> <username>admin</username> <password>admin</password> </server> </servers> </settings>
idは任意。後でpom.xmlに記述するサーバーの識別子です。で、pom.xmlにはbuildのところに次のように追加。もちろんリポジトリの設定もする必要あります(http://geekswithblogs.net/jolson/archive/2006/03/09/71857.aspx)。
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <version>1.0-SNAPSHOT</version> <configuration> <server>local_tomcat</server> </configuration> </plugin> </plugins> </build>
configurationにserverとしてsettings.xmlに記述したserverのidを書きます。
あとは、http://mojo.codehaus.org/tomcat-maven-plugin/deployment.htmlで紹介されているように使うだけ。
To avoid copying resources to the build directory, the webapp source directory can be deployed to Tomcat by typing:mvn war:inplace tomcat:inplace
へー、target以下にwarのイメージを作らないでdeployしてくれるんだって。あ、でも、src/main/webapp/WEB-INFにlibとclassesができちゃうのね。使わないでおこう。
やっぱり、良く使うのは以下の2つでしょう。
mvn tomcat:deploy (war作ってdeploy) mvn war:exploded tomcat:exploded (war作らずdeploy)