Search code examples
mavenbeanshellmaven-invoker-plugin

Running a Post-Build Script via maven-invoker-plugin


I am trying to run a simple beanshell script to print 'Hello World' after building the war file. I am making references from this. However, I keep getting "No projects were selected for execution." after running mvn clean install. I am unsure if the error comes from the directories of the files or I am unable to just print 'Hello World' after the war file is built.

   +- project folder/
      +- buildTargetWarFileFolder/
      +- python/
         +- folder/
         |  +-helloWolrd.bsh
           <plugin>
             <artifactId>maven-invoker-plugin</artifactId>
                <version>3.2.1</version>
                <configuration>
                    <debug>true</debug>
                    <projectsDirectory>project folder</projectsDirectory>
                    <postBuildHookScript>python/folder/helloWorld.bsh</postBuildHookScript>
                </configuration>
                <executions>
                    <execution>
                        <id>print Hello World</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Solution

  • I would recommend using the exec:exec goal directly, binding to the integration-test phase of the maven build (to try out your python script).

          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
              <executable>python</executable>
              <arguments>
                <argument>-c</argument>
                <argument>print('Hello world')</argument>
              </arguments>
            </configuration>
            <executions>
              <execution>
                <id>integration-test</id>
                <phase>integration-test</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
    

    This is the same as running the following on the command line after your war is created:

    python -c "print('Hello world')"