2010-10-28 34 views
9

這怎麼能在windows下工作?Maven Exec插件不能在Windows上使用系統路徑?

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.2</version> 
    <executions> 
    <execution> 
     <id>deploy-dev-ssh</id> 
     <phase>install</phase> 
     <goals> 
     <goal>exec</goal> 
     </goals> 
    </execution> 
    </executions> 
    <configuration> 
    <executable>echo</executable> 
    <arguments> 
     <argument>hello</argument> 
    </arguments> 
    </configuration> 
    </plugin> 

我得到這個當我運行它:

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:exec (do-this) on project <my_project_name>: Command execution failed. Cannot run program "echo" (in directory "<my_local_path>"): CreateProcess error=2, The system cannot find the file specified -> [Help 1] 

如何回聲無法對路徑?

回答

9

這裏的問題是echo是cmd.exe程序的一個命令,它不像Unix一樣是一個獨立的進程\應用程序。爲了做你在這裏要做的事情,你需要調用cmd作爲可執行文件'echo','/ C'(告訴cmd你傳遞給它一個命令 - 參見Windows上的'cmd /?'命令行。)和'hello'作爲參數。

像這樣:

  <configuration> 
       <executable>cmd</executable> 
       <arguments> 
        <argument>/C</argument> 
        <argument>echo</argument> 
        <argument>hello</argument> 
       </arguments> 
      </configuration> 
3

您也可以在運行目錄下創建一個echo.bat文件,內容設置爲:

@echo %*

這種技術是同時支持特別方便Windows和Linux構建環境。也許「回聲」不是一個好例子,但是你可能遇到在Windows和Linux上都存在相同命令的情況。

相關問題