How to use Maven exec plugin in Eclipse?

4.6k views Asked by At

I'm new to Maven and I'm trying to run a project with exec:java. My build fails, presumably because I don't have the exec plugin. I downloaded the plugin (http://mvnrepository.com/artifact/org.codehaus.mojo/exec-maven-plugin), but now I don't know what to do with it in order to be able to use it in Eclipse. I tried adding it to the build path, but that didn't seem to work. This may be a very stupid question, but how do I get the plugin to work?

Here's my build output:

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Twitter2 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:1.4.0:java (default-cli) @ Twitter2 ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.826 s
[INFO] Finished at: 2015-06-11T14:24:29-06:00
[INFO] Final Memory: 10M/114M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java (default-cli) on project Twitter2: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java are missing or invalid -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException
1

There are 1 answers

5
M A On BEST ANSWER

As the error says, it seems the mainClass parameter, which tells the plugin what class to run, is not set properly. See http://www.mojohaus.org/exec-maven-plugin/java-mojo.html for the usage of the java goal of the plugin. Try adding the parameter in the POM configuration:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <configuration>
         <mainClass>fully.qualified.class.name</mainClass>
    </configuration>
</plugin>

Or via property -Dexec.mainClass=fullClassName in the command line.