1

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?

3
  • have you add the exec-maven-plugin in you pom.xml? Commented Apr 21, 2014 at 10:18
  • Yes i have. I edited my poste Commented Apr 21, 2014 at 10:23
  • A bit too late, but I found this very similar question : stackoverflow.com/questions/10108374/… Commented Jan 4, 2018 at 16:39

3 Answers 3

1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

Even if i add the correct plugin, i obtain the same error. I edited the original poste
The error now is just: Invalid task '1': you must specify a valid lifecycle phase, or a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal
if your project is jar file, then you should configure as jar in pom.xml and running command also by jar.
0

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.

2 Comments

Even if i add the correct plugin, i obtain the same error. I edited the original poste
The error now is just: Invalid task '1': you must specify a valid lifecycle phase, or a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.