WARファイル作成
パッケージ
それでは、この調子で意気揚々とパッケージを試みてみます。
# mvn package [INFO] Scanning for projects... [INFO] ---------------------------------------------------------------------------- [INFO] Building sample [INFO] task-segment: [package] [INFO] ---------------------------------------------------------------------------- [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Nothing to compile - all classes are up to date [INFO] [resources:testResources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:testCompile] [INFO] No sources to compile [INFO] [surefire:test] [INFO] No tests to run. [INFO] [war:war] [INFO] Exploding webapp... [INFO] Copy webapp webResources to /root/work/mavenproject/sample/target/sample [INFO] Assembling webapp sample in /root/work/mavenproject/sample/target/sample [INFO] Generating war /root/work/mavenproject/sample/target/sample.war [INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Error assembling WAR: Deployment descriptor: /root/work/mavenproject/sample/target/sample/WEB-INF/web.xml does not exist. [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2 seconds [INFO] Finished at: Fri Jul 07 11:17:07 JST 2006 [INFO] Final Memory: 6M/19M [INFO] ------------------------------------------------------------------------
む、web.xmlが存在しないと怒られてしまいました。。。
maven-compiler-plugin
コンパイルプラグインを使って、ソースディレクトリとターゲットディレクトリを変更出来ないかと思い、とりあえずmaven-compiler-pluginを入れてみる事にしました。
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <fork>true</fork> <compileVersion>1.4.2</compileVersion> <executable>/opt/IBMJava2/bin/javac</executable> </configuration> </plugin>
まず、ソースディレクトリとターゲットディレクトリの設定ではなく、実際にコンパイルに使用するJDKを指定する設定を行いました。
- fork
- mavenが使用しているJDKではなく、別のJDKを指定するかどうかを設定 true=使用する/false=使用しない
- compileVersion
- 使用するコンパイラのバージョン
- executable
- 使用するコンパイラの絶対パス
# mvn compile [INFO] Scanning for projects... [INFO] ---------------------------------------------------------------------------- [INFO] Building sample [INFO] task-segment: [compile] [INFO] ---------------------------------------------------------------------------- [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] Compiling 1 source file to /root/work/mavenproject/sample/target/classes [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2 seconds [INFO] Finished at: Fri Jul 07 11:51:19 JST 2006 [INFO] Final Memory: 4M/13M [INFO] ------------------------------------------------------------------------
と、とりあえずプラグインが稼働する事が確認できました。
pom.xmlでソースディレクトリとターゲットディレクトリの設定
何か、とぼけた事をしていたようです。
そもそもpom.xmlでソースディレクトリとターゲットディレクトリの設定ができるじゃないですか。
- sourceDirectory
- ソースディレクトリを相対パスで定義
- scriptSourceDirectory
- スクリプトソースディレクトリを相対パスで定義
- testSourceDirectory
- テストソースディレクトリを相対パスで定義
- outputDirectory
- ソースファイルの出力ディレクトリを相対パスで定義
- testOutputDirectory
- テストソースファイルの出力ディレクトリを相対パスで定義
<build> <sourceDirectory>src/main/JavaSource</sourceDirectory> </build>
sourceDirectoryを追加し、ソースをsrc/main/javaからsrc/main/JavaSourceとする事でコンパイルが通りました。
続いてテストソースを設定します。
<build> <testSourceDirectory>src/main/JavaSourceUT</testSourceDirectory> </build>
続いてスクリプトソースを設定します。
<build> <scriptSourceDirectory>src/main/WebContent</scriptSourceDirectory> </build>
む、これではWEB-INFなどの設定ファイルを見に行ってくれないらしい。
WebContentのままではうまく通らないみたいなので、WebContentをwebappに変更しました。
その場合、Packageも正常動作しました。