2015-12-02 86 views
1

我有一個maven多模塊項目分層如下。Maven包裝屬性文件

test-integration 
    - test-integration.properties 
test-services 
    - test-services.properties 
test-persistence 
    - test-persistence.properties 

在每個項目中都有一個屬性文件。我應該如何配置maven以從jar中排除所有* .properties,同時將它們全部提取到配置文件夾中?

  • 測試集成/目標/ LIB /測試integration.jar
  • 測試集成/目標/ LIB /測試service.jar中
  • 測試集成/目標/ LIB /測試的持久性。罐子
  • 測試集成/目標/配置/ test-integration.properties
  • 測試集成/目標/配置/ test-service.properties
  • 測試集成/目標/配置/ test-persistence.properties

回答

0

您可以在聚合/父項目增加(使之適用於所有申報模塊)如下:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <version>2.6</version> 
      <configuration> 
       <outputDirectory>${project.build.directory}/lib</outputDirectory> 
       <excludes> 
        <exclude>**/test-*.properties</exclude> 
       </excludes> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-resources-plugin</artifactId> 
      <version>2.7</version> 
      <executions> 
       <execution> 
        <id>copy-resources</id> 
        <phase>package</phase> 
        <goals> 
         <goal>copy-resources</goal> 
        </goals> 
        <configuration> 
         <outputDirectory>${project.build.directory}/conf</outputDirectory> 
         <resources> 
          <resource> 
           <directory>src/main/resources</directory> 
           <includes> 
            <include>test-*.properties</include> 
           </includes> 
          </resource> 
         </resources> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

在細節:

  • Maven的Jar插件是從包裝的jar中除去屬性文件,並且它還將target目錄配置爲lib(如你在你的問題中所述)
  • Maven資源插件正在拷貝到target/conf目錄(同樣,如你所描述的ab Ove)由測試開始並由src/main/resources文件夾提供的任何屬性文件。

我在一個示例項目中測試,它工作正常。

另請注意:您的IDE可能會將conf目錄顯示爲您項目的一部分(將其視爲新的目錄資源,它發生在我身上的Eclipse):這不是創建的新文件夾,而是顯示在一個不同的觀點。如果你真的不想有這個副作用,那麼考慮使用maven-antrun-plugin而不是Resources插件。