0

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>
Russ1337
  • 51
  • 1
  • 6
  • What is the intention of the script? Why do you need a script after the war has been built? – khmarbaise Dec 04 '20 at 11:31
  • I want to automate the process of creating a python virtual environment after the war file is built. I am using a simple Hello World script right now as I am trying to figure out whether the invoker plugin can be used to achieve what I want. i.e. running any beanshell script after building the war file. – Russ1337 Dec 05 '20 at 18:04
  • Take a look here: https://maven.apache.org/plugins/maven-invoker-plugin/examples/post-build-script.html – khmarbaise Dec 05 '20 at 18:32
  • I am not getting any success with the invoker plugin so far. May I ask how does the invoker plugin differ from this: http://www.mojohaus.org/exec-maven-plugin/? – Russ1337 Dec 08 '20 at 17:34
  • What I don't understand yet is why do you need python environment in relationship with a WAR ? Do you want to write test/integration tests? – khmarbaise Dec 08 '20 at 21:53
  • I want to automate the process of creating a python virtual environment after the .war file is built. This is because there are some classes in the project which require specific python versions to execute. While I am not writing test/integration tests for this project, I wish to run a script to create the python virtual environment via the pom.xml after the .war file is built. – Russ1337 Dec 09 '20 at 03:32
  • I've tried this: mojohaus.org/exec-maven-plugin, what happens is the build will fail should the script exit with any error. That being said, I believe the invoker plugin is the correct plugin to use. Is there a way I can make use of what the plugin does to locate and run a .bsh file? – Russ1337 Dec 09 '20 at 05:39
  • Hm... sorry to say why using python within a java project? What is advantage of that? Why is it needed? The point is invoker is intended to write integration tests for maven plugins ... – khmarbaise Dec 09 '20 at 09:42
  • 1
    To answer your question, I am using the python script to execute some calculations/simulations with python libraries before consuming the data in the java project. I am now convinced that I am unable to use the invoker plugin as it it for integration tests. I am close to achieving what I need with the exec plugin. Thank you so much for the replies. – Russ1337 Dec 09 '20 at 09:54

1 Answers1

0

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')"
Jody Garnett
  • 503
  • 3
  • 10
  • The maven invoker plugin is complicated, and intended for building small maven projects and running them, and then verifying the results. You *can* use `maven-invoker-plugin` setup a small maven project in `src/it/hello/pom.xml`, that itself uses the `exec:exec` goal to run your python hello world script. But that approach is too complicated to live. – Jody Garnett Mar 19 '22 at 00:33