Reputation: 2228
When I run my Maven project from Netbeans everything works properly. However, when i use the command line:
mvn exec:java -Dexec.mainClass="Main.Laucher" -Dexec.args=$args1 $args2 $args3
I obtain this error:
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Invalid task '1': you must specify a valid lifecycle phase, or a goal in the format plugin:goal or
pluginGroupId:pluginArtifactId:pluginVersion:goal
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Mon Apr 21 12:06:23 CEST 2014
[INFO] Final Memory: 7M/491M
The maven version is :
Apache Maven 2.2.1 (rdebian-8)
Java version: 1.7.0_51
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: fr_FR, platform encoding: UTF-8
OS name: "linux" version: "3.2.0-58-generic" arch: "amd64" Family: "unix"
In pom.xml
i have exec-maven-plugin
:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>simulation.amazon.Laucher</mainClass> </configuration> </plugin>
How can I resolve this error?
Upvotes: 1
Views: 1556
Reputation: 782
I am having the same issue with my maven project in IntelliJ and I found an alternative way to make it work, even without the exec-maven-plugin. I was able to build the project by following this answer and including a default goal in the following pom.xml file:
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Then, even though the project could be build, whenever I used command line parameters in the run configuration, I had the same issue that the first argument was considered the lifecycle's name. So, instead of defining a new Maven run configuration, I chose a normal Application. After selecting the main class and defining the program parameters as well, everything worked.
Similarly, if you must run your java program from the command line, you can avoid this error by first building your project and then calling your main class. I specifically did:
mvn package
java -cp target/myproject-1.0-SNAPSHOT-jar-with-dependencies.jar run.MyMain "a" "b" "c" "d"
and it worked fine. It looks like a sufficient workaround in comparison to
mvn exec:java -Dexec.mainClass=run.MyMain "a" "b" "c" "d"
and Intellij's maven configuration that might show unexpected errors.
Upvotes: 0
Reputation: 7894
You have added the plugin as a dependency which is incorrect. You should add it as a plugin.
<build>
<plugins>
<plugin>
<groupId>org.co dehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
</plugin>
</plugins>
</build>
I don't really see how it is working in NetBeans but this configuration is definitely required for it to work via the command line.
Upvotes: 0
Reputation: 15
you need to configure exec-maven-plugin
plugin your pom.xml
for example:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
...
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.Main</mainClass>
<arguments>
<argument>argument1</argument>
...
</arguments>
<systemProperties>
<systemProperty>
<key>myproperty</key>
<value>myvalue</value>
</systemProperty>
...
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
Upvotes: 1