Milan Rathod
Milan Rathod

Reputation: 33

unable to execute shell script in java maven project in windows

My project pom contains gmaven-plugin plugin in which under configuaration->properties->script tag, sh script location is defined and when I am executing mvn install, I am getting below error on my windows machine.

java.io.IOException: 
Cannot run program ": CreateProcess error=193, %1 is not a valid Win32 application

Please find below relevant plugin.

        <plugin>
            <groupId>org.codehaus.gmaven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <version>1.4</version>
            <executions>
                <execution>
                    <phase>initialize</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <properties>
                            <script>${basedir}/../tools/testfile.sh</script>
                        </properties>
                        <source>
                            //some code for execution
                        </source>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Upvotes: 1

Views: 1401

Answers (1)

Gyanendra Dwivedi
Gyanendra Dwivedi

Reputation: 5538

You are trying to execute a shell script on windows machine. The window command does not know how to do that. this is probably creating the issue.

If you would like to test this, just replace shell with a simple .bat file (Window executable).

You can add below into the .bat file and try mvn install

echo Test file executed.
echo I am too lazy to write commands again and again.

EDIT: As OP informed via comment

.bat file is executing successfully from when executing mvn install command but what if you want to execute only .sh file only. Is there any way for it.

Now the option is to execute the .sh on windows. Few option are to install GIT client, which by default installs GIT BASH which is a unix like command prompt.

Once install, just open any .sh file from windows and say open with.. and choose GIT BASH. Click on Always use this program. This step would associate .sh to the git bash program.

Git Bash

Another usual solution to that is use Cygwin

Upvotes: 1

Related Questions