The way to run Java main using MAVEN (both Java application projects) can be resolved as follows:
1. Import the MAVEN project into eclipse, then direct the project right-click "Run as", "Java application".
2. Directly specify the main portal of the jar package (ref.: http://www.cnblogs.com/EasonJim/p/6481704.html), package the jar file with the Maven command, and then run the Java-jar Application.jar.
3, through the MAVEN plugin Exec-maven-plugin implementation command line directly run. Official website: http://www.mojohaus.org/exec-maven-plugin/
The exec-maven-plugin is used as follows (from: http://blog.csdn.net/qbg19881206/article/details/19850857):
One, run from the command line
1, compile the code before running,Exec:java will not automatically compile the code, you need to manually execute MVN compile to complete the compilation.
2. After compiling, execute exec to run the main method.
① does not need to pass parameters:
MVN exec: Java
② need to pass parameters:
MVN exec: Java
③ Specifies run-time dependencies on classpath:
MVN exec: Java
Second, specify a stage to execute in Pom.xml
<Build> <Plugins> <plugin> <groupId>Org.codehaus.mojo</groupId> <Artifactid>Exec-maven-plugin</Artifactid> <version>1.1.1</version> <executions> <Execution> <Phase>Test</Phase> <Goals> <goal>Java</goal> </Goals> <Configuration> <MainClass>Com.jsoft.test.MainClass</MainClass> <arguments> <argument>arg0</argument> <argument>Arg1</argument> </arguments> </Configuration> </Execution> </executions> </plugin> </Plugins> </Build>
Tip: This approach uses a plug-in way to configure the lifecycle to trigger a specified plug-in to run a specific task. The above configuration shows that the <phase> Specifies the life cycle phase of MAVEN, and that <goal> has the exec plugin target java.
Binding the execution of the Mainclass.main () method to the test phase of MAVEN, the following command allows you to execute the Main method:
Third, specify a configuration in Pom.xml to perform
<Profiles> < Profile> <ID>Code-mainclass</ID> <Build> <Plugins> <plugin> <groupId>Org.codehaus.mojo</groupId> <Artifactid>Exec-maven-plugin</Artifactid> <version>1.1.1</version> <executions> <Execution> <Phase>Test</Phase> <Goals> <goal>Java</goal> </Goals> <Configuration> <MainClass>Com.jsoft.test.MainClass</MainClass> <arguments> <argument>arg0</argument> <argument>Arg1</argument> </arguments> </Configuration> </Execution> </executions> </plugin> </Plugins> </Build> </ Profile> </Profiles>
Tip: This approach uses the build configuration file , where <id> is the flag parameter triggered by the profile,<phase> Specifies the MAVEN lifecycle phase, and < Goal> has developed the exec plugin target for Java.
Execute the main method by specifying the configuration file, as follows:
MVN Test-pcode-mainclass
Note: Additional configuration parameter descriptions for MVN exec can be obtained from the following command.
MVN exec: help-ddetail=true-dgoal=java
How to run Java Ain using maven (GO)