2014-02-20 53 views
0

我想在我的包(基於Spring動態模塊的OSGI)中引入屬性文件。我想保留屬性文件中的數據庫URL,用戶名,密碼等屬性,並希望maven從該文件讀取。Maven不讀取應用程序屬性文件

我想在我的POM介紹過濾:

<properties> 
    <database.username>${development_user}</database.username> 
</properties> 
<build> 
    <filters> 
     <filter>src/main/resources/Application_${env}.properties</filter> 
    </filters> 
    <resources> 
     <resource> 
      <directory>src/main/resources</directory> 
      <filtering>true</filtering> 
     </resource> 
    </resources> 
    <defaultGoal>install</defaultGoal> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-resources-plugin</artifactId> 
      <version>2.4</version> 
      <executions> 
       <execution> 
        <id>bundle</id> 
        <phase>package</phase> 
        <goals> 
         <goal>resources</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <version>2.8</version> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.felix</groupId> 
      <artifactId>maven-bundle-plugin</artifactId> 
      <version>2.3.7</version> 
      <extensions>true</extensions> 
      <executions> 
       <execution> 
        <id>bundle</id> 
        <phase>package</phase> 
        <goals> 
         <goal>bundle</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <excludes>*/pom.</excludes> 
       <instructions> 
        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> 
        </instructions> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

我有以下特性在我Application_local.properties文件:

development_user=dev_user 

但是當我通過建立與捆綁命令「MVN全新安裝-Denv = local「系統在我的database.xml中插入'$ {development_user}'作爲值

有人能幫我解決這個問題嗎?

+0

是database.xml放在src /主/資源? – UR6LAD

回答

1

試試這個一

 <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>properties-maven-plugin</artifactId> 
      <version>1.0-alpha-2</version> 
      <executions> 
       <execution> 
        <id>read</id> 
        <phase>validate</phase> 
        <goals> 
         <goal>read-project-properties</goal> 
        </goals> 
        <configuration> 
         <files> 
          <file>src/main/resources/Application_${env}.properties</file> 
         </files> 
        </configuration> 
       </execution>     
      </executions> 
     </plugin> 
+0

太棒了!是的,這就像魔術一樣工作!非常感謝鮑里斯:) –

相關問題