maven プロジェクトの作成 archtypeArtifactId を指定する
mvn archetype:generate
だけで対話形式でプロジェクトを作成すると、
元となる archetype
の選択に 2300 以上の選択肢が表示されてしまう。
生成時に、 archetypeArtifactId
を指定することで、回避することができる。
コマンドラインツールを作成する時
maven-archetype-quickstart を指定する。 (デフォルトでもある)
$ mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart
webアプリを作成する時
$ mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp
その他に指定できるオプション
オプション | 説明 |
---|---|
-Dversion |
version |
-DgroupId |
groupId |
-DartifactId |
artifactId |
-DinteractiveMod |
archetypeArtifactId が指定されている場合は、この設定値を true にすることで、インタラクティブモードをスキップできる |
ex: archetypeとgroupId,artifactIdを指定して作成。
$ mvn archetype:generate \ > -DarchetypeArtifactId=maven-archetype-quickstart \ > -DgroupId=sample \ > -DartifactId=hello [INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom --- [INFO] Generating project in Interactive mode [INFO] Using property: groupId = sample [INFO] Using property: artifactId = hello Define value for property 'version' 1.0-SNAPSHOT: : [INFO] Using property: package = sample Confirm properties configuration: groupId: sample artifactId: hello version: 1.0-SNAPSHOT package: sample Y: :
実行するためのプラグイン のインストール
exec-maven-plugin プラグインを使えば以下のように簡単に成果物を実行することができる
$ mvn exec:java
エントリーファイルは configration で指定する。
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.6.0</version> <executions> <execution> ... <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>com.example.Main</mainClass> <arguments> <argument>argument1</argument> ... </arguments> <systemProperties> <systemProperty> <key>myproperty</key> <value>myvalue</value> </systemProperty> ... </systemProperties> </configuration> </plugin> </plugins> </build>
configration
要素において以下の値を設定できる