Reputation: 61
I've tried and follow this solution How to read an external properties file in Maven but with no luck.
I would like to read an absolute path(/home/tomcat/lib) from a properties file(which is in the same location as pom.xml) and set the value in the pom.xml
project.properties file contains:
myTomCat.lib.location=/home/tomcat/lib
pom.xml configuration contains:
<properties>
<envTomcatLib>${myTomCat.lib.location}</envTomcatLib>
</properties>
<dependencies>
<dependency>
<artifactId>MyJar</artifactId>
<groupId>MyJar</groupId>
<scope>system</scope>
<version>1.0</version>
<systemPath>/${envTomcatLib}/MyJar.jar</systemPath>
</dependency>
</dependencies>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/project.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
The problem is either at eclipse compile time or running "mvn install" that the placeholder ${envTomcatLib}/MyJar.jar, can't get resolved to /home/tomcat/lib/MyJar.jar and remains ${envTomcatLib}/MyJar.jar.
Can someone please assist?
Thanks
Upvotes: 1
Views: 12513
Reputation: 114
You may need to remove "/"
before /${envTomcatLib}/MyJar.jar
or give property value as home/tomcat/lib
instead of /home/tomcat/lib
. It may be the reason for not able to resolve your location.
Upvotes: 0
Reputation: 14951
Values in the <properties>
section are assigned when the POM is initially loaded. The properties-maven-plugin
only affects plugin executions that come after the point where the properties were loaded. More detail in a similar answer I provided.
BTW, the Maven Reference Book has this to say about system scope: "Note that this scope is not recommended (you should always try to reference dependencies in a public or custom Maven repository)."
Upvotes: 1