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

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!

Related

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

exec-maven plugin error when executing with mvn clean verify

I get the below error when executing postman tests using exec Maven plugin. What am I doing wrong?
I am fairly new to this, so, any help would be welcomed.
I run it with 'mvn clean verify'
Error:-
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:exec (merge) on project ihtests: Command execution failed.
Plugin:-
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<workingDirectory>.</workingDirectory>
</configuration>
<executions>
<execution>
<id>merge</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>
/node_modules/newman/bin/newman.js
</executable>
<arguments>
npm shipment-tests
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Maven - skip execution step with a flag?

I have this code in my pom.xml (inside a <plugin>)
<execution>
<id>npm</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>ci</arguments>
</configuration>
</execution>
<execution>
<id>Run Unit Tests</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>run test</arguments>
</configuration>
</execution>
Is there a way i can pass a flag when i run mvn clean install that will skip the Run Unit Tests execution step?
You can probably do the following.
Define under <properties> something like <run.unit.tests.skip>false</run.unit.tests.skip>
Add <skip>${run.unit.tests.skip}</skip> to the configuration of the execution.
Then mvn clean install -Drun.unit.tests.skip=true would the command line call.

how to execute multiple command prompt commands using maven in single pom.xml

I want to run multiple command prompt commands in maven using single pom.xml. How can I do that?
For ex: I have 2 commands to execute. I am executing the first command by using exec-maven-plugin.
Below is the portion of my pom.xml to execute the first command:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>load files</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>windchill</executable>
<arguments>
<argument>wt.load.LoadFileSet</argument>
<argument>-file</argument>
<argument>${basedir}/fileSet.xml</argument>
<argument>-UNATTENDED</argument>
<argument>-NOSERVERSTOP</argument>
<argument>-u</argument>
<argument>wcadmin</argument>
<argument>-p</argument>
<argument>wcadmin</argument>
</arguments>
</configuration>
</plugin>
For this the build is success.
Is it possible to execute one more command just like above in the same pom.xml? I was not able to do that. So someone please help how to add it in pom.xml
The answer can be found in the FAQ.
The full answer is here: http://article.gmane.org/gmane.comp.java.maven-plugins.mojo.user/1307
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>id1</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cmd1</executable>
</configuration>
</execution>
<execution>
<id>id2</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cmd2</executable>
</configuration>
</execution>
</executions>
</plugin>
Then you specify execution ids as:
mvn exec:exec#id2
But this syntax is possible starting from maven 3.3.1

Running Gradle from Maven

I'm looking for some Gradle executor plugin for Maven (similar to Maven ant-run plugin).
Google did not help. Is it possible that such plugin doesn't exist?
I should try this:
https://github.com/if6was9/gradle-maven-plugin
This is a maven plugin that makes it easy to invoke gradle from maven.
It is similar to the maven-antrun-plugin that allows ant to be invoked
from maven.
I probably would use:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>test</id>
<phase>test</phase>
<configuration>
<executable>./gradlew</executable>
<arguments>
<argument>test</argument>
<argument>-i</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>install</id>
<phase>install</phase>
<configuration>
<executable>./gradlew</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
Because of the following reasons:
I would prefer to trust in a plugin maintained by Codehaus.
If you use the gradle-maven-plugin, probably you'll have to configure additional information in your settings.xml. Otherwise this error can occur: Failed to execute goal org.fortasoft:gradle-maven-plugin:1.0.8

Resources