2014-07-23 65 views
0

我有一個包含3個模塊的模塊化Maven項目。在那些(WEB)中的一個,配置文件變量沒有被識別爲一個環境變量,但它需要它的闕的真實姓名,如下圖所示:Maven Profile變量web項目不工作

<Principal POM> 
    <Module App-core> 
    <Module ejb>  
    <Module web> 

在主要POM,有3個簡檔全髖關節置換具有不同的值相同的輪廓propertie:

<profile1> 
    <environment>value1</environment> 

<profile2> 
    <environment>value2</environment> 

<profile3> 
    <environment>value3</environment> 

該變量被用作依賴分類變量,如下:

<dependency> 
    <groupId>com.test</groupId> 
    <artifactId>app-core</artifactId> 
    <version>1.0.0</version> 
    <classifier>${environment}</classifier> 
</dependency> 

在行家編譯階段,僅在網絡臨ject,它不會使用變量值更改變量名稱。

任何幫助?

+0

你如何啓用配置文件? – user944849

回答

0

我已經解決了問題。

我已經將配置文件複製到配置文件中。我曾多次依賴

這是代碼的配置文件1

<profile> 
    <id>profile1</id> 
<properties> 
<environment>value1</environment> 
</properties> 
    <dependency> 
     <groupId>com.test</groupId> 
     <artifactId>app-core</artifactId> 
     <version>1.0.0</version> 
     <classifier>${environment}</classifier> 
    </dependency> 
</profile> 

這是代碼的profiles2

<profile> 
    <id>profile2</id> 
<properties> 
<environment>value2</environment> 
</properties> 
    <dependency> 
     <groupId>com.test</groupId> 
     <artifactId>app-core</artifactId> 
     <version>1.0.0</version> 
     <classifier>${environment}</classifier> 
    </dependency> 
</profile> 

而這個代碼是對Profile3的

<profile> 
    <id>profile3</id> 
<properties> 
<environment>value3</environment> 
</properties> 
    <dependency> 
     <groupId>com.test</groupId> 
     <artifactId>app-core</artifactId> 
     <version>1.0.0</version> 
     <classifier>${environment}</classifier> 
    </dependency> 
</profile> 
0

標籤profile1 profile2 profile3不啓用替換屬性。要做到這一點,你必須改變你的父POM這樣

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

    <profiles> 
     <profile> 
      <id>profile1</id> 
       <properties> 
        <environment>value1</environment> 
       </properties> 
     </profile> 

     <profile> 
      <id>profile2</id> 
       <properties> 
        <environment>value2</environment> 
       </properties> 
     </profile> 

     <profile> 
      <id>profile3</id> 
       <properties> 
        <environment>value2</environment> 
       </properties> 
     </profile> 
    </profiles> 
</project> 

現在,你必須運行MVN安裝-P配置文件1爲yourprojectname

+0

我解決了這個問題。你的例子不工作。謝謝 –