2013-05-13 51 views
0

我是apache Maven中的新手。當我嘗試從屬性文件中讀取值時,它不會選取值。我已經在SO中看到過所有以前提過的問題。但沒有運氣。這是我的財產文件。Maven:無法從Proprties獲得屬性值文件

nameofmayil=mayilsamy 

這是的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.mycompany.mayil</groupId> 
    <artifactId>mayil-app</artifactId> 
    <version>1.0.1</version> 
    <packaging>jar</packaging> 

    <name>mayil-app</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies>  
     <dependency> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>properties-maven-plugin</artifactId> 
     <version>1.0-alpha-2</version> 
     </dependency> 

    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 


    <dependency> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-antrun-plugin</artifactId> 
     <version>1.6</version> 
    </dependency> 
    </dependencies> 

    <scm> 
    <connection>scm:svn:http://127.0.0.1/svn/my-project</connection> 
    <developerConnection>scm:svn:https://127.0.0.1/svn/my-project</developerConnection> 
    <tag>HEAD</tag> 
    <url>http://127.0.0.1/websvn/my-project</url> 
    </scm> 

    <build> 
     <plugins> 

      <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>properties-maven-plugin</artifactId> 
        <version>1.0-alpha-2</version> 
        <executions> 
        <!-- Associate the read-project-properties goal with the initialize phase, to read the properties file. --> 
        <execution> 
         <phase>initialize</phase> 
         <goals> 
         <goal>read-project-properties</goal> 
         </goals> 
         <configuration> 
         <files> 
          <file>${basedir}/buildNumber.properties</file> 
          <file>${basedir}/mayil.properties</file> 
         </files> 
         <quite>false</quite> 
         </configuration> 
        </execution> 
        </executions> 
       </plugin> 

       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-antrun-plugin</artifactId> 
        <version>1.6</version> 
        <executions> 
        <execution> 
         <phase>validate</phase> 
         <goals> 
         <goal>run</goal> 
         </goals> 
         <configuration> 
         <target> 
          <echo>Displaying value of properties</echo> 
          <echo>${nameofmayil}</echo> 
         </target> 
         </configuration> 
        </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
</project> 

屬性文件被加載正確,我與檢查。

+0

您可以顯示生成日誌嗎?你使用什麼命令來運行構建? – Dmitry 2013-05-13 11:29:12

+0

$ mvn install ... – Arung 2013-05-13 11:34:45

+0

好的,你運行'mvn install'會得到什麼輸出?請將此信息添加到問題中。 – Dmitry 2013-05-13 11:41:44

回答

2

顯示的POM的properties-maven-plugin執行綁定到initialize階段,並且antrun插件目標顯示綁定到validate階段的屬性。 initialize之後validate(根據Maven lifecycle docs)這就是爲什麼你沒有看到你想要的結果。您可以在幾個方面解決:

  • 綁定properties-maven-plugin目標到validate階段OR
  • 綁定的maven-antrun-plugin目標到initialize階段

兩個以上的有目標綁定到同一階段。這很好,只要目標按您希望它們執行的順序在POM中列出。如果您希望它們綁定到不同的階段,請執行這兩個步驟。