Maven cho phép bạn xác định các thuộc tính trong POM của dự án. Bạn có thể làm điều này bằng cách sử dụng tập tin POM tương tự như sau:
<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>
Bạn có thể tránh xác định tài sản trong thẻ properties
, và vượt qua giá trị từ dòng lệnh như:
mvn -Dserver.url=http://localhost:8080/manager/html some_maven_goal
Bây giờ, nếu bạn không muốn chỉ định chúng từ dòng lệnh và nếu bạn cần tách biệt thêm các thuộc tính này từ dự án POM, thành tệp thuộc tính, thì bạn sẽ cần sử dụng Properties Maven plugin và chạy mục tiêu read-project-properties
trong initialize phase of the Maven lifecycle . Ví dụ từ trang plugin được sao chép ở đây:
<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>
Nguồn
2011-08-22 08:20:22
Công trình này !! .. Cảm ơn bạn!! –