2011-12-05 75 views
6

我想擁有一些變量屬性值並使用Maven配置文件來獲取正確的輸出。我已經完成了我的hibernate xml,log4j.properties並沒有問題。maven變量屬性過濾

因此,它在我在項目#1中工作,我在/ src/main/resources下有一堆文件。我設置屬性和資源的行家過濾如下:

<properties> 
    <log.level>DEBUG</log.level> 
</properties> 


<profiles> 
    <profile> 
     <id>production</id> 
     <properties> 
    <log.level>INFO</log.level> 
     </properties> 
    </profile> 
</profiles> 

<build> 
    <resources> 
     <resource> 
      <directory>src/main/resources</directory> 
      <filtering>true</filtering> 
     </resource> 
    </resources> 
</build> 

以上沒有問題的工作。 但是,在我的項目#2中 - 我有一些文件具有可變屬性,但它們位於/ src/main/webapp/WEB-INF下 - 除上述目錄指向WEB- INF,它不起作用。我試圖在項目#2中將文件放在/ src/main/resources下,並且工作正常。

在我看來,當文件位於/ src/main/webapp/WEB-INF下時,資源過濾有問題,但是我需要該文件在那裏,因此當戰爭生成時它會進入WEB-INF文件夾。

有沒有人有指示如何做到這一點?

下面是實現不工作pom.xml中以下snipet(資源過濾完全被忽略)

<properties> 
     <wsdl.url>http://stage/wsdl-url</wsdl.url> 
</properties> 

<profiles> 
    <profile> 
     <id>production</id> 
     <properties> 
    <wsdl.url>http://prod/wsdl-url</wsdl.url> 
     </properties> 
    </profile> 
</profiles> 

<build> 
    <resources> 
     <resource> 
      <directory>src/main/webapp/WEB-INF</directory> 
      <filtering>true</filtering> 
     </resource> 
    </resources> 
</build> 

回答

5

我也有這個問題;我懷疑POM的主要<resources>部分由戰爭插件忽略,所以我來了直接配置插件:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-war-plugin</artifactId> 
    <configuration> 
     <filters> 
      <filter>filter.properties</filter> 
     </filters> 
     <webResources> 
      <resource> 
       <directory>WebContent/WEB-INF</directory> 
       <filtering>true</filtering> 
       <targetPath>WEB-INF</targetPath> 
      </resource> 
     </webResources> 
    </configuration> 
</plugin> 
+0

感謝 - 這正是我需要的 –