我目前正在处理使用 maven 的问题。我在使用 Maven 构建软件时尝试更新文件。出于某种原因,我必须使用 powershell 脚本并在使用 mvn 构建时运行它。这是我的代码:
<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>
它没有按预期工作,有人可以帮助我吗?
最佳答案
这条消息有一段时间了,但我在最后几天完成了练习。关键是按照说明使用 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>"& { Set-AuthenticodeSignature '${project.build.directory}/Logging_Functions/*.psm1' @(Get-ChildItem ${project.build.certificate.path} -codesigning)[0]"}</argument>
</arguments>
</configuration>
</execution>
关于maven - 如何在maven中运行powershell脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20112421/