maven - 如何在maven中运行powershell脚本

标签 maven powershell

我目前正在处理使用 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>"&amp; { 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/

相关文章:

powershell - 在同一行上获取日期和时间

powershell - Powershell脚本无法将ForEach-Object识别为有效的cmdlet

java - 尝试使用 Alfresco Maven SDK 打包时出现 "Could not import bootstrap model"

java - 将Spring boot war文件部署到Tomcat时如何指定配置文件?

java - 如何从 src 文件夹调用测试类并使用 maven 构建

java - 如何从命令行激活 Maven 配置文件(构建子系统)

maven - spring-boot-maven-plugin,mvn 发布 :prepare not committing changes to pom. xml

powershell - 在 Powershell 中将 x XML 节点设置为值

excel - 在使用 PowerShell 保存/关闭之前,等待刷新 Excel 工作簿中每个工作表中的外部数据连接

sql-server - 在 ssis foreach 容器中运行 powershell 脚本时没有结果