Running Maven Exec Plugin Inside Eclipse

31,094

Solution 1

  1. go to Run menu -> run configurations
  2. you should see a "Maven Build" item on the list of the left, double click it to create a new configuration of that type
  3. name it as you want
  4. browse workspace to select the base directory of your project
  5. set exec:java as the goal, and exec.mainClass / yourClass as parameters.

This is how it looks on my set-up:

enter image description here

PD: if you have set the mainClass argument on the pom.xml, then the parameter from the execution will be disregarded.

Solution 2

In pom.xml set the target class:

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                <configuration>
                       <mainClass>org.sonatype.mavenbook.weather.Main</mainClass>
                </configuration>
                </execution>
            </executions>

Then go to "Run as.. " -> "Maven build..." -> Goals "exec:java"

Solution 3

There's slight mistake in the pom.xml entry given by @grin. The correct one should be as follows:

<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>org.sonatype.mavenbook.weather.Main</mainClass>
    </configuration>
</plugin>

Solution 4

go to Run menu -> run configurations you should see a "Maven Build" item on the list of the left, double click it to create a new configuration of that type name it as you want browse workspace to select the base directory of your project set exec:java as the goal, and exec.mainClass / yourClass as parameters.

it worked for me Thanks !

Share:
31,094
knpwrs
Author by

knpwrs

With Ken Powers comes Ken Responsibility

Updated on July 16, 2022

Comments

  • knpwrs
    knpwrs almost 2 years

    Using m2eclipse, what is the simplest way to use the Codehaus Mojo Exec Plugin to launch my project without leaving eclipse? So far on the pom plugins screen I have set up the org.codehuas.mojo plugin.

    Specifically, I would like to execute the following from inside eclipse:

    mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main
    
  • Vamsi Nerella
    Vamsi Nerella almost 9 years
    how would I configure if my main class accepts arguments?