2013-11-21 235 views
0

我目前正在使用maven处理一个问题。我尝试使用maven构建软件时更新文件。出于某种原因,我必须使用powershell脚本,并在使用mvn构建时运行它。这里是我的代码:如何在maven中运行powershell脚本

<exec executable="powershell.exe" 
         spawn="true"> 
        <arg value="/c"/> 
        <arg value="myReplace.ps1"/> 
        <arg value="../../the/path/to/the/directory/" /> 
        <arg value ="filename"/> 
        <arg value="value1" /> 
        <arg value="value2" /> 
        <arg value="value3" /> 
      </exec> 

它没有按预期工作,有人可以帮助我吗?

+2

请给我们错误信息 –

+0

这看起来很像Ant。你说过(并标记Maven)。那个怎么样?你不想只使用[Exec Maven Plugin](http://mojo.codehaus.org/exec-maven-plugin/usage.html)? –

回答

0

这条消息可能来自一段时间,但我在最后几天经历了这个练习。关键是按照说明使用exec插件。以下是项目的pom.xml中的示例:

以下代码在PowerShell模块脚本上启动代码签名。请注意,命令字符串必须从命令行调用PowerShell函数,其中&未被Maven正确消解。逃避它的伎俩。对于更复杂的操作,请调用PS脚本。

... 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      <version>1.3.2</version> 
      <executions> 
       <execution> 
        <id>scripts-package</id> 
        <goals> 
         <goal>exec</goal> 
        </goals> 
        <phase>prepare-package</phase> 
        <configuration> 
       <!-- optional --> 
        <workingDirectory>/Temp</workingDirectory> 
        <arguments> 
         <argument>-command</argument> 
         <argument>"&amp; { Set-AuthenticodeSignature '${project.build.directory}/Logging_Functions/*.psm1' @(Get-ChildItem ${project.build.certificate.path} -codesigning)[0]"}</argument> 
        </arguments> 
        </configuration> 
       </execution>