【问题标题】:Access properties of maven property plugin访问maven属性插件的属性
【发布时间】:2016-02-13 21:29:07
【问题描述】:

我在回答这个问题Specify system property to Maven project 时包含了 maven 属性插件。为了能够从文件中设置我的数据库属性(并在测试环境中使用 maven 参数覆盖它)。但是,如果我尝试通过访问其中一个属性 System.getProperty("mysql.url") 例如 null 返回。如何从设置属性目标访问属性集。

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>

【问题讨论】:

    标签: java maven properties-file


    【解决方案1】:

    尝试添加阶段:

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

    如果使用阶段初始化,则可以使用阶段'initialize'之后的属性

    【讨论】:

    • 这并没有改变任何东西
    • 我想在获得数据库连接的方法中使用它,如编辑后的代码所示
    • 当你使用这个方法initializeDatabaseConfiguration,如果你使用executable-jar whit main-class,你可以使用resources>filtering?
    • 您能否给出更详细的答案,我将如何使用资源过滤来做到这一点?
    猜你喜欢
    • 2014-01-28
    • 1970-01-01
    • 2016-05-31
    • 2013-01-23
    • 2011-11-25
    • 2020-12-22
    • 2013-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多