0

I included the maven property plugin like proposed in a response to this question Specify system property to Maven project. In order to be able to set my database properties from file (and override it with maven parameters in testing environment). However if I try to access one of the properties via System.getProperty("mysql.url") for example null is returned. How can I access the properties set from set properties goal.

private void initializeDatabaseConfiguration() {
    url = System.getProperty("mysql.url");
    con = DriverManager.getConnection(url, username, password);

}


   <plugin>
       <groupId>org.codehaus.mojo</groupId>
       <artifactId>properties-maven-plugin</artifactId>
       <version>1.0-alpha-2</version>
       <executions>
           <execution>
               <phase>initialize</phase>
               <goals>
                   <goal>set-system-properties</goal>
               </goals>
               <configuration>
                   <files>                          
                      <file>src/main/resources/config.properties</file>
                   </files>
                   <properties>
                       <property>
                           <name>mysql.url</name>
                           <value>${mysql.url}</value>
                       </property>
                   </properties>
               </configuration>
           </execution>
       </executions>
   </plugin>
Community
  • 1
  • 1
PKuhn
  • 1,288
  • 13
  • 29

1 Answers1

0

Try to add phase:

<execution>
<phase>initialize</phase>
 <goals>
   <goal>set-system-properties</goal>
 </goals>

If you use the phase initialize, you can use the propriets after phase 'initialize'

question_maven_com
  • 2,263
  • 14
  • 19