How to run powershell script in maven

maven, powershell

Solution

This message dates from a while but I went through the exercise in the last days. The key is to use the exec plugin as stated. Here is an example in a project's pom.xml:

The code below launches the code-signing on a PowerShell module script. Note that the command string must begin, for calling PowerShell functions from the command line, with & which is not properly digested by Maven. Escaping it does the trick. For more complex operations, call a PS script.

...
        <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>

Problem

I currently dealing with a problem using maven. I try to update a file when building the software using maven. For some reason, I have to use a powershell script and run it when building using mvn. Here is my code: ``` <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> ``` It does not work as expected, can someone help me?

Original source