Three ways to run Java main using maven

Maven uses the exec plug-in to run the Java main method. Here are three different operation modes.

1、 Run from the command line

1. Compile the code before running. Exec: Java will not compile the code automatically. You need to manually execute MVN compile to complete the compilation.

2. After compilation, execute exec and run the main method.

No parameters need to be passed:

Parameters to be passed:

Specify runtime dependencies on classpath:

2、 In POM Specify a stage to execute in XML

Connect codegenerator The execution of the main () method is bound to the test phase of Maven. You can execute the main method through the following command:

3、 In POM Specify a configuration in XML to execute

After wrapping the configuration in 2 with the < profile > tag, you can execute the main method by specifying the configuration file, as follows:

Note: other configuration parameter descriptions of MVN exec can be obtained through the following commands.

summary

The above is all about the analysis of the three operation modes of running Java main with Maven. If there are any deficiencies, please leave a message. Interested friends can continue to refer to: Java uses future to obtain multi-threaded running results in time, talk about the difference between static and non static in Java, detailed explanation of Java multi-threaded forkjoinpool instance, etc. I hope it will be helpful to you. Thank you for your support!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>