【问题标题】:execute windows powershell script using pom.xml使用 pom.xml 执行 windows powershell 脚本
【发布时间】:2018-03-05 06:22:42
【问题描述】:

我想用 Maven 执行 windows powershell 脚本。这是我尝试过的:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.1.1</version>
    <executions>
        <execution>
            <id>some-execution</id>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>D:\Projects\test.ps1</executable>
    </configuration>
</plugin>

但它只是在执行 pom 时打开 powershell 脚本

mvn exec:exec

【问题讨论】:

    标签: maven powershell maven-3 pom.xml


    【解决方案1】:

    没有其他选项,所以在批处理文件中写下一行

    PowerShell -NoProfile -ExecutionPolicy unrestricted -Command D:\Projects\Test.ps1
    

    并使用exec插件调用批处理文件,该文件将执行powershell脚本。

    喜欢

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.1.1</version>
        <executions>
            <execution>
                <id>some-execution</id>
                <goals>
                    <goal>exec</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <executable>D:\Projects\test1.bat</executable>
        </configuration>
    </plugin>
    

    【讨论】:

    • 所以你知道了如何正确运行 ps1 文件。为什么不将批处理文件中的完整命令行放到可执行标记中?
    • 已经有了,第一行 PowerShell -NoProfile -ExecutionPolicy unrestricted -Command "PathTo ps1 file"
    • 没有。我的意思是放置完整的 cmdline 而不是 bat 文件 &lt;executable&gt;D:\Projects\test1.bat&lt;/executable&gt;
    • 顺便说一句。使用 Powershell 运行文件的正确参数是 -File,而不是 -Command
    • 这是个好主意。那么就没有必要保留球拍了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-25
    • 2013-08-19
    • 2012-05-31
    • 2020-08-12
    • 2011-06-06
    相关资源
    最近更新 更多