0

I want to execute windows powershell script with Maven. Here is what I tried:

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

But it is just opening the powershell script while executing the pom

mvn exec:exec

1 Answer 1

1

Doesn't got any other option so write below line in batch file

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

and use the exec plugin to call the batch file, which will execute the powershell script.

Like

<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>
Sign up to request clarification or add additional context in comments.

5 Comments

So you figured out how to run a ps1 file properly. Why don't you put that complete command line you have in your batch file to the executable tag?
it's already there, the first line PowerShell -NoProfile -ExecutionPolicy unrestricted -Command "PathTo ps1 file"
No. I meant to place the complete cmdline instead of the bat file <executable>D:\Projects\test1.bat</executable>
And BTW. the proper parameter to run a file with Powershell would be -File, not -Command
That is a good idea. Then there is no need of keeping the bat also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.