2014-02-20 50 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

太棒了!是的,这就像魔术一样工作!非常感谢鲍里斯:) –

相关问题