I am trying to run a Java project using Maven, need help on how to run
I tried with various options, Run As > Maven clean, Run As > Maven Install, Run As > Maven test, etc. But the output is not showing in the console though build is successful
I am using eclipse and able to run java file using Run As > Java Application
My Build tag in pom.xml
 <build>
    <plugins>
        <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
                <source>1.6</source>
                <target>1.6</target>
        </configuration>
     </plugin>
        <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
       <version>1.6.0</version>
        <configuration>
             <mainClass>mypackage.classnamehavingmain</mainClass>
        </configuration>
        </plugin>
    </plugins>
   </build>
                Run as Java Application - We can run any Java application/project using this option. It doesn't matter whether project is Maven or Ant or Gradle. It should work if we have main method in a class.
You should add the goal for execution
 <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
          <execution>
            <goals>
              <goal>your_goal_name</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <mainClass>com.example.Main</mainClass>
        </configuration>
      </plugin>
and then to execute you can perform :
 mvn exec:your_goal_name
                        If you would like to run it from the terminal you can do mvn compile exec:java -Dexec.mainClass=mypackage.classnamehavingmain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With