I wrote a simple cli program to get input from the CLI when invoking. I was able to do this by adding the exec plugin in the pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.mavericks.App</mainClass>
<arguments>
<argument>names.txt</argument>
<argument>expense.txt</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
But when I try to invoke the same thing via cli
mvn exec:java -Dexec.mainClass=“com.mavericks.App” -Dexec.args=“'names.txt' 'expense.txt'”
Unknown lifecycle phase "expense.txt”". You must specify a valid lifecycle phase or a goal. Help would be much appreciated.
As per slinlok's comment it worked with these above modification,
mvn exec:java -Dexec.mainClass=com.mavericks.App -Dexec.args="names.txt expense.txt"
thanks.
Related
Below is the relevant part of my POM -
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>StartHub</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>${basedir}/src/lib/Hub/selenium-server-standalone-2.53.0.jar</argument>
<argument>-role</argument>
<argument>hub</argument>
<argument>-throwOnCapabilityNotPresent</argument>
<argument>false</argument>
<argument>-newSessionWaitTimeout</argument>
<argument>20000</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>StartNode</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>${basedir}/src/lib/Node/selenium-server-standalone-2.53.0.jar</argument>
<argument>-hub</argument>
<argument>http://127.0.0.1:4444/register/grid</argument>
<argument>-port</argument>
<argument>5555</argument>
<argument>
Dwebdriver.chrome.driver=${basedir}/chromedriver.exe</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
I was trying to use the exec plugin to execute a jar(selenium standalone server) in two configurations(hub and Node).
My issue is that the jar is executed only once in the configuration specified between the first pair of "execution" tags. I have searched extensively for a solution and the only thing I found was that the id's for different executions need to be different, which I rectified. I still can't seem to manage to run the jars twice even though I can run any one of them successfully if I comment out the execution of the other.
I should also mention that I'm running the project in Eclipse, so ideally what I would want to do is right-click on the POM.xml click on Run-as and select "Maven test".
This is not a Maven executions issue but rather an issue related to what you are executing: a blocking process (the first server) which would stop the build listening for a node which would never get connected (because its execution won't start).
Changing your pom to the following:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>StartHub</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-version</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>StartNode</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-version</argument>
</arguments>
</configuration>
<a/execution>
</executions>
</plugin>
It would perfectly execute the two exec executions, printing twice the Java version. Note: the snippet is a copy and paste from your question, just replacing arguments of the java command to its version option.
What you are most probably looking for is to execute the two commands in background or at least in a non-blocking way in order to get the second executed, then proceed with the build (to execute some tests I presume).
Check this SO question on how to achieve it: instead of using the exec-maven-plugin, use the maven-antrun-plugin to launch the two selenium commands.
As a further note, you should probably consider using the maven-failsafe-plugin instead and execute integration tests, attaching the executions above to the pre-integration-test phase and stop them during the post-integration-test phase in order to properly clean them.
I am quite new with using maven options - so sorry for an easy question.
I have asked beforehand about how to run java code (call function) and get a clear answer.. but
it seems something is wrong in this config. Or is it because I am not using a correct parameters for startup?
<build>
<plugins>
....
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.package.Separator.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
I am running my POM with $: mvn exec:exec
And I get such error:
One or more required plugin parameters are invalid/missing for 'exec:exec'
[0] Inside the definition for plugin 'exec-maven-plugin' specify the following:
<configuration>
...
<executable>VALUE</executable>
</configuration>
-OR-
on the command line, specify: '-Dexec.executable=VALUE'
I have read something about this error and tried originally to move the configuration to executions
secondly - specify classpath but nothing happened((
My Main function in Separator.java class is like this:
static public void main(String[] arg) throws ParserConfigurationException, TransformerException, SAXException, IOException {
//and here I call for example
System.out.println("LOL");
}
Some people use: package before goals (for previous versions) but it does not solve my issue.
I have rewrite my POM:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.package.Separator</mainClass>
</configuration>
</plugin>
But now Class not found exception at org.package.Separator
I am using mvn package for compile
I am running my POM with $: mvn exec:exec And I get such error:
Actually you should run
$: mvn exec:java
See example described on exec-maven-plugin:java usage.
Finnaly your plugin description should be as follows:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<id>default-cli</id>
<!--<phase>validate</phase>--> <!-- or any other phase you want. -->
<phase>integration-test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.package.Separator</mainClass>
</configuration>
</plugin>
Note! This plugin will work only on full name declaration in console or via phase execution:
$: mvn org.codehaus.mojo:exec-maven-plugin:1.3.2:java
$: mvn integration-test
First try renaming the classpath of your project org.package.Separator.Main
"package" is used in java namespace syntax, so don't use it in your packages classpath.
And maybe you should try adding phase to your goal like this :
...
<executions>
<execution>
<phase>run</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.package.Separator.Main</mainClass>
</configuration>
</execution>
</executions>
...
and execute : mvn compile run
I had the same problem. My problem was my code was NOT in src/main/java. your class containing main method must be under src/main/java
I am trying to attach an exec process to a maven build. I want to build a secondary dependency (that is actually a Clojure project build with maven) every time I build the maven project.
Currently, I have the pom.xml below, but the exec process is just not running. The maven documentation is not that much help.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>compile-with-lein</id>
<phase>initialize</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>lein</executable>
<commandlineArgs>install</commandlineArgs>
<workingDirectory>../nrepl-clojure</workingDirectory>
</configuration>
</plugin>
I am making a maven project which is trying to run command prompt commands. I tried Exec Maven Plugin but couldn't do it. I think i'm at wrong way for this. Here is my work for making a file with "Exec Maven Plugin". Can someone make an explanation why this is not working or make a suggestion about new plugin or solution which is working at pom.xml (not Ant).
`<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>mkdir</executable>
<arguments>
<argument>C:\Users\USERNAME\Desktop\FILENAME</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>`
Thank You..
This is just a workaround you can try until someone comes up with a better answer. (I will remove it afterwards probably)
Instead of executing commands directly, you can create a bash/batch script and try to execute that. For example:
<execution>
<id>Some ID</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/scripts/do_stuff.sh</executable>
</configuration>
</execution>
It's basically the same thing, but you can use the normal syntax in the script, instead of the XML syntax in the POM file.
I've a sniped like the following on my pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.StartTestMain</mainClass>
<arguments>
<argument>target/classes/local.testrun</argument>
</arguments>
</configuration>
</plugin>
While it executes without problems, I find that return code is ignored and there is no way for StartTestMain to tell the build that it should fail.
I'm thinking about propagating an Exception hoping that maven will take it and stop the build. However, this will fail if exec-maven-plugin is ever configured in forkMode.
Any cleaner options?