2016-11-11 171 views
0

我想將一些本地配置文件添加到maven mavenprojekt的類路徑中。 這些文件「config-local」應該覆蓋我的資源目錄中的現有默認配置文件。 所以只有當目錄「config-local」存在時,默認配置文件纔會被本地配置替換。如果文件夾Y存在,Maven覆蓋類路徑中的文件

我試圖將dir作爲資源添加到我的maven Build中,但它不起作用,而且我不確定如果config-local不存在會發生什麼情況。

回答

0

的答案很簡單:

Maven的資源插件增加了反聲明順序的資源:

<build> 
    <sourceDirectory>src/main/java</sourceDirectory> 
    <resources> 
     <!-- The resources will be placed in reversed order in the war 
      that means first entry will be added as last resource and may override other resources --> 
     <resource> 
      <!-- ATTENTION! we need the config-local declration at first cause it shall be placed as last resource in the classpath --> 
      <directory>config-local</directory> 
     </resource> 
     <resource> 
      <directory>src/main/java</directory> 
      <includes> 
       <include>**/*.xml</include> 
       <include>**/*.properties</include> 
      </includes> 
     </resource> 
     <resource> 
      <directory>src/main/resources</directory> 
     </resource> 
    </resources> 

只是移動在上面的配置本地資源,它會被添加爲最後的資源和可能會覆蓋其他默認文件。 如果文件夾不存在,Maven會毫無問題地跳過它。