1.mvnコマンドで以下をEclipseのworkspaceで実行
$ mvn archetype:generate -DgroupId=com.test
-DartifactId=TestApp
-DarchetypeArtifactId=maven-archetype-webapp
-DinteractiveMode=false
2.WTPプロジェクトに変換
$ mvn eclipse:eclipse -Dwtpversion=2.0
3.pom.xml、web.xmlを自分用に編集していく
参考リンク
http://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/
2014年11月7日金曜日
2014年9月16日火曜日
MavenでOutOfMemoryが出る場合の対処法
MavenでOutOfMemoryが出る場合、MAVEN_OPTSでVMの最大値を大きく取ってやると解決する。
export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=128m"
https://cwiki.apache.org/confluence/display/MAVEN/OutOfMemoryError
2014年1月29日水曜日
Mavenでテストのフェーズを無視して実行するには
Mavenでテストのフェーズは完了してるので、ここをスキップしてパッケージしたwarファイルをサーバーにインストールしたい場合などには、便利なオプションがあったのでメモしておきます。
% mvn install -Dmaven.skip.test=true
% mvn package -Dmaven.skip.test=true
結構単純なフラグを指定してやるだけで、テストフォーズをとばしてくれます。便利。
http://www.mkyong.com/maven/how-to-skip-maven-unit-test/
% mvn install -Dmaven.skip.test=true
% mvn package -Dmaven.skip.test=true
結構単純なフラグを指定してやるだけで、テストフォーズをとばしてくれます。便利。
http://www.mkyong.com/maven/how-to-skip-maven-unit-test/
2013年12月18日水曜日
tomcat-maven-pluginでTomcatのmanagerアプリにアクセスする際の認証情報の設定について
MavenでwarファイルをTomcatにインストールして、サーバーを再起動したりするにはtomcat-maven-pluginとTomcatのmanagerアプリの設定で可能です。そして、Tomcatのmanagerアプリにアクセスするには認証情報が必要になるのですが、これをpom.xmlファイルに書いてしまうと、Gitなどのバージョンコントロールシステムで管理するには内容が丸見えなので問題あり。そこで、どこに認証情報を書くのかというと、Mavenにはsettings.xmlとファイルがあるので、ここにサーバー情報を記述。
settings.xml
<servers>
<server>
<id></id>
<username></username>
<password></password>
</server>
</servers>
このsettings.xmlのサーバーIDはpom.xmlのtomcat-maven-pluginのサーバー情報と紐付いてる。
2013年12月13日金曜日
Mavenのmaven-war-pluginのfilterとprofileで変数を設定してやれば、環境毎にwarパッケージを作成できる。
Mavenのmaven-war-pluginとprofileで変数を設定してやれば、環境毎にwarパッケージを作成できます。物凄い便利。
ポイントは、
http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html
http://www.manydesigns.com/en/portofino/portofino3/tutorials/using-maven-profiles-and-resource-filtering
http://erhan.me/2011/10/20/property-substitution-for-web-xml-with-using-profile-properties-maven-pom-xml/
ポイントは、
- maven-war-pluginのwebResourceで環境毎に設定したい設定ファイルを列挙
- webResourceで列挙したファイルにfilterを使ってやる
- profileで環境毎のproperties変数を定義してやる
実行する時は、mvn package -P dev, mvn package -P productionみたいな感じでwarを作成できる。
http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html
http://www.manydesigns.com/en/portofino/portofino3/tutorials/using-maven-profiles-and-resource-filtering
http://erhan.me/2011/10/20/property-substitution-for-web-xml-with-using-profile-properties-maven-pom-xml/
MavenでJavascriptやStylesheetのファイルはYUI compressor Maven MOJOを使う
MavenでJavascriptやStylesheetのファイルはYUI compressor Maven MOJOを使うと便利です。JSやCSSファイルをデフォルトで-minという名前で圧縮してくれるし、aggregationタグでは圧縮したファイルを一括してくれる。
http://alchim.sourceforge.net/yuicompressor-maven-plugin/index.html
ハマったところと言えば、Mavenのライフサイクルのフェーズがprepare-packageじゃないと思った順序でpom.xmlの内容が動作してくれなかった点。
http://alchim.sourceforge.net/yuicompressor-maven-plugin/index.html
ハマったところと言えば、Mavenのライフサイクルのフェーズがprepare-packageじゃないと思った順序でpom.xmlの内容が動作してくれなかった点。
ラベル:
CSS,
JavaScript,
Maven,
YUI
2013年12月5日木曜日
Mavenで署名付きjarを作るにはmaven-jar-pluginとmaven-jarsigner-pluginを使う
署名付きアプレットを作るのにMavenでどうやってやればいいのかまとめてみました。まずは手順:
1.2.はmavenを走らせる前に予め作っておきました。3.4. はcompileのフェーズで実行。サンプルのpom.xmlは以下:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>make-a-jar</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<includes>
<include><!-- Include files--></include>
</includes>
<outputDirectory><!-- Output directory --></outputDirectory>
<finalName><!-- jar name --></finalName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version>
<configuration>
<archive><!-- jar file --></archive>
<keystore><!-- keystore file --></keystore>
<storepass><!-- password--></storepass>
<alias><!-- alias --></alias>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<id>sign-a-jar</id>
<phase>compile</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
http://maven.apache.org/plugins/maven-jar-plugin/usage.html
http://stackoverflow.com/questions/3598424/jar-signing-strategy-in-maven-projects
http://stackoverflow.com/questions/4757426/maven-specify-the-outputdirectory-only-for-packaging-a-jar
- keystoreを予め作っておく
- jarをおいておくフォルダを予め作っておく
- maven-jar-pluginでjarを作る
- maven-jarsigner-pluginで署名付きjarを作る
1.2.はmavenを走らせる前に予め作っておきました。3.4. はcompileのフェーズで実行。サンプルのpom.xmlは以下:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>make-a-jar</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<includes>
<include><!-- Include files--></include>
</includes>
<outputDirectory><!-- Output directory --></outputDirectory>
<finalName><!-- jar name --></finalName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version>
<configuration>
<archive><!-- jar file --></archive>
<keystore><!-- keystore file --></keystore>
<storepass><!-- password--></storepass>
<alias><!-- alias --></alias>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<id>sign-a-jar</id>
<phase>compile</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
http://maven.apache.org/plugins/maven-jar-plugin/usage.html
http://stackoverflow.com/questions/3598424/jar-signing-strategy-in-maven-projects
http://stackoverflow.com/questions/4757426/maven-specify-the-outputdirectory-only-for-packaging-a-jar
登録:
投稿 (Atom)