Maven では、プロジェクトの POM でプロパティを定義できます。これは、次のような POM ファイルを使用して行うことができます。
<project>
...
<properties>
<server.url>http://localhost:8080/manager/html</server.url>
</properties>
...
<build>
<plugins>
<plugin>
...
<configuration>
<url>${server.url}</url>
<server>tomcat</server>
</configuration>
...
</plugin>
</plugins>
</build>
</project>
タグ内でプロパティを指定することを避けproperties
、コマンド ラインから次のように値を渡すことができます。
mvn -Dserver.url=http://localhost:8080/manager/html some_maven_goal
これらのプロパティをコマンド ラインから指定したくない場合や、これらのプロパティをプロジェクト POM からプロパティ ファイルにさらに分離する必要がある場合は、Properties Maven プラグインread-project-properties
を使用して、その目的を実行する必要があります。 Maven ライフサイクルの初期化フェーズで。プラグイン ページの例をここに再現します。
<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<!-- Associate the read-project-properties goal with the initialize phase, to read the properties file. -->
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>etc/config/dev.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>