2014-02-25 126 views
1

我是Maven插件的新手,我需要讓這個插件運行sencha cmd工具來縮小我們的JavaScript應用程序,作爲日常構建過程的一部分。如何在此Maven插件中設置路徑?

當前可執行標籤有一個硬編碼路徑,但我想知道是否可以指定路徑作爲環境變量,然後在下面的代碼中訪問該環境變量,以便它可以在任何機器上運行?

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.2.1</version>      
    <executions> 
     <execution> 
      <id>sencha-compile</id> 
      <phase>compile</phase> 
      <goals> 
       <goal>exec</goal> 
      </goals> 
      <configuration> 
       <executable>C:\Sencha\Sencha\Cmd\4.0.2.67\sencha.exe</executable> 
       <arguments> 
        <argument>app</argument> 
        <argument>build</argument> 
       </arguments> 
      </configuration> 
     </execution> 
    </executions> 
</plugin>    
+0

什麼[webminifier - Maven的插件] (http://mojo.codehaus.org/webminifier-maven-plugin/)?爲什麼使用外部程序? – khmarbaise

+0

Sencha Cmd工具可以解析ExtJS應用程序中各種JavaScript文件之間的依賴關係。如果這些依賴關係未解決,縮小會生成無法運行的代碼。 –

回答

0

要回答你的問題,你可以從一個Maven POM文件中引用系統環境變量使用此語法: ${env.NAME_OF_VARIABLE}

請參閱此鏈接瞭解詳情: https://maven.apache.org/pom.html#Properties

如果你命名環境變量PATH_TO_SENCHA_EXE你可以這樣引用它: <executable>${env.PATH_TO_SENCHA_EXE}sencha.exe</executable>

作爲環境變量的替代方案,您可以考慮在您的pom中創建一個屬性以包含此路徑。然後,您可以通過在命令行中傳遞屬性的新值或通過在您的pom中加載可能包含此屬性的屬性文件來更改用於不同環境的值。這裏有很多選擇。

編輯: 我發現後者的建議已經覆蓋上SO通過以下鏈接(可能其他地方):

Reading properties file from Maven POM file

+0

我喜歡爲路徑創建pom屬性的想法,然後在命令行上設置該值。但是我沒有在你的鏈接中看到該技術的參考。 –

+0

好的。通過鏈接查看我的編輯示例。 – user2747594

0

檢查我的煎茶ExtJS的5 +煎茶Cmd的5 + Maven的集成示例在: https://github.com/dobromyslov/sencha-extjs-maven

你必須設置環境變量:

  • 出口它在控制檯通過:

    $出口SENCHA_CMD = 「/路徑/到/你/煎茶/加利福尼亞/ 5.0.0.116 /煎茶」

  • 你也可以將此導出語句添加到您的~/.bashrc/etc/profile文件,以使其永久。

  • 或者在Windows上添加新的環境變量。

集煎茶Cmd的編譯環境:

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <!-- Default build environment --> 
    <sencha.env>production</sencha.env> 
</properties> 

<profiles> 
    <!-- Development profile --> 
    <profile> 
     <id>dev</id> 
     <activation> 
      <property> 
       <name>env</name> 
       <value>development</value> 
      </property> 
     </activation> 
     <properties> 
      <sencha.env>testing</sencha.env> 
     </properties> 
    </profile> 

    <!-- Production profile --> 
    <profile> 
     <id>prod</id> 
     <activation> 
      <property> 
       <name>env</name> 
       <value>production</value> 
      </property> 
     </activation> 
     <properties> 
      <sencha.env>production</sencha.env> 
     </properties> 
    </profile> 
</profiles> 

然後使用以下Maven插件:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.2.1</version> 
    <executions> 
     <execution> 
      <id>sencha-compile</id> 
      <phase>compile</phase> 
      <goals> 
       <goal>exec</goal> 
      </goals> 
      <configuration> 
       <!-- Set path to your Sencha Cmd executable--> 
       <executable>${env.SENCHA_CMD}</executable> 
       <arguments> 
        <argument>-sdk</argument> 
        <argument>${basedir}/src/main/webapp</argument> 
        <argument>app</argument> 
        <argument>build</argument> 
        <argument>--clean</argument> 
        <argument>--environment</argument> 
        <argument>${sencha.env}</argument> 
        <argument>--destination</argument> 
        <argument>${basedir}/src/main/webapp/build</argument> 
       </arguments> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

和運行

$ mvn compile