Maven consente di definire le proprietà nel POM del progetto. È possibile farlo utilizzando un file POM simile al seguente:
<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>
si può evitare specificando la proprietà all'interno del tag properties
, e passare il valore dalla riga di comando come:
mvn -Dserver.url=http://localhost:8080/manager/html some_maven_goal
Ora, se non si desidera specificarli dalla riga di comando e se è necessario isolare ulteriormente queste proprietà dal progetto POM, in un file di proprietà, sarà necessario utilizzare lo Properties Maven plugin ed eseguire l'obiettivo read-project-properties
nello initialize phase of the Maven lifecycle . L'esempio dalla pagina dei plugin è qui riprodotto:
<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>
fonte
2011-08-22 08:20:22
Questo funziona !! .. Grazie!! –