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

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>

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')"

Related

How to skip the build of jar file "app-source.jar" when maven build happens in SpringBoot?

I have following jar's when in run mvn clean package command
app.jar
app-source.jar
app.jar.original
I dont want the app-source.jar to be generated when I run the above maven command.
I have added
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<finalName>app</finalName>
<addResources>false</addResources>
<arguments>-Dmaven.source.skip=true</arguments>
<includeSystemScope>false</includeSystemScope>
</configuration>
<executions>
<!--<execution>
<id>skip-sources</id>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
The below specified attribute 'attach' will disable the sources.jar not included in the artifact list
<attach>false</attach>
</configuration>
</execution>-->
<execution>
<id>build-info</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<!--The below specified attribute 'attach' will disable the sources.jar not included in the artifact list-->
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>
SprinBoot Version : 2.7.5
Maven Source Plugin version : 3.2.0
The goal executed in maven build
[INFO] --- maven-source-plugin:3.2.0:jar-no-fork (attach-sources) # app
[INFO] Building jar: path\to\project\target\app-sources.jar
Thanks
Rohit

maven `exec:exec` fails but `exec:java` succeeds

I learned that the Exec Maven Plugin have two goals, exec:exec, and exec:java, but I don't know how to specify them:
In my case, the mvn exec:java works well, but the mvn exec:exec keeps throwing exceptions like below:
[INFO] --- exec-maven-plugin:1.6.0:exec (run) # allnewmaker ---
[ERROR] Command execution failed.
java.io.IOException: Cannot run program "exec" (in directory "/home/huang/Desktop/Project/Make/allnewmaker"): error=2, No such file or directory
at java.lang.ProcessBuilder.start (ProcessBuilder.java:1048)
at java.lang.Runtime.exec (Runtime.java:620)
at org.apache.commons.exec.launcher.Java13CommandLauncher.exec (Java13CommandLauncher.java:61)
at org.apache.commons.exec.DefaultExecutor.launch (DefaultExecutor.java:279)
at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:336)
at org.apache.commons.exec.DefaultExecutor.execute (DefaultExecutor.java:166)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:804)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:751)
my pom.xml is like this:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>bar</id>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>foo</id>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<!--default: java-->
<executable>exec</executable>
<arguments>
<argument>-i</argument>
<argument>${argInput}</argument>
<argument>-o</argument>
<argument>${argOutput}</argument>
</arguments>
<mainClass>org.qoros.maker.AllNewMaker</mainClass>
</configuration>
</plugin>
</plugins>
in your pom you have the name of your executable:
exec
And the name "exec" is not a valid executable name.
You configure your goal there:
<execution>
<id>bar</id>
<goals>
<goal>exec</goal>
</goals>
</execution>
If you want to use exec:java, you need to change your goal from exec to java.
I am referring the usage page:
https://www.mojohaus.org/exec-maven-plugin/usage.html
Let me know if something need clarification!

Execute sh script during build

I have this plugin in pom.xml
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution><!-- Run our version calculation script -->
<id>Version Calculation</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<workingDirectory>${basedir}/target/process.properties</workingDirectory>
<executable>${basedir}/Scripts.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
Process.Properties file
link.item=true
link.process=false
link.process.run=Downloads_Item.txt$
Scripts.sh
#!/bin/bash
sed 's/Downloads_Item/Downloads_Item_NiteVate/g' Process.properties
I am trying to replace the value of the flag link.process.run by executing Scripts.sh.
I tried but its not worked. This should happen while taking build.
I am not able to find where is the problem

Maven: ant-run plugin echo does not seem to execute

I have a maven project that is using the ant-run plugin. I added an echo message but it does not seem to execute:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ast-application-deployment-kit</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo message="Starting ant-run target configuration."/>
But when I mvn clean package, I see this
[INFO] --- maven-antrun-plugin:1.3:run (my-app) # my-app ---
[INFO] Executing tasks
[INFO] Executed tasks
But I do not see the echo. What am I doing wrong?
Consider upgrading your plugin version to the latest (1.8):
This POM snippet prints echo:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<echo>NOW YOU CAN SEE ME!</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

Maven execute external jar file

In my project I have a .jar file called validator.jar in main/resources.
I want to validate the package that I made with by running this .jar file, both with maven.
What I tried so far is:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>src/main/resources/validator.jar</executable>
<arguments>
<argument>-f target/PROJECT-${project.version}-el6.myext</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
This runs the jar, but doesn't seem to take in the arguments.
on the commandline it should look like this (this works):
java -jar -f target/PROJECT-1.0-el6.myext
Try this:
<arguments>
<argument>-f</argument>
<argument>target/PROJECT-${project.version}-el6.myext</argument>
</arguments>

Resources