In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use maven's exec-maven-plugin plug-in". The content in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use maven's exec-maven-plugin plug-in".
Brief introduction
Maven's exec-maven-plugin plug-in is mainly used to execute executable jar package commands, many tools provide command-line interaction, such as mybatis-generator, each run will hit a long command, very troublesome.
Sometimes, you want to provide a 3-party package for comparison people to use, in order to allow others to run the program with a very simple command, you can use the exec-maven-plugin plug-in.
Of course, it can also be implemented as a script, but the versatility of the script is not very good, you have to provide scripts such as run.bat,run.sh. Such problems can be avoided through exec-maven-plugin.
The exec-maven-plugin plug-in has two directories (goal), one is java and the other is exec. Here is a brief explanation of maven's goal, you can think of maven's goal as a specific function, a maven plug-in may have many functions, one function is a goal,maven and the concept of life cycle, maven has three sets of life cycle, respectively, clean,default,site. Each life cycle contains the following phases (phase), and each phase can be seen as a process. Participate in the following maven lifecycle. For example, execute the following two commands:
Mvn clean packagemvn clean test
The above two commands contain two lifecycles, clean and default lifecycles. Clean executes the pre-clean and clean phases of the clean lifecycle, the mvn clean package command executes from the default lifecycle from the validate to the package phase, and the mvn clean test command from the validate phase of the default lifecycle to the package phase.
Plug-ins are executed by binding goal to a specified stage of life. It is maven that checks which plug-ins' goal is bound to this phase when executing the corresponding phase, and then executes these goal.
If you have doubts about this knowledge, it is strongly recommended to read "maven practice".
Instance java destination public class App {public static void main (String [] args) {for (String arg: args) {System.out.println (arg);}
The above code is very simple, printing main method parameters.
4.0.0 cn.freemethod plugin 0.0.1-SNAPSHOT jar plugin http://maven.apache.org UTF-8 1.2.1 junit junit 4.9 test org.codehaus.mojo Exec-maven-plugin ${exec_maven_plugin_version} test java Cn.freemethod.plugin.App arg0 arg1
Looking at the configuration above, we bound the java template (goal) of the exec-maven-plugin plug-in to the test phase of the default lifecycle. So all we have to do is execute the following command:
Mvn testexec destination import java.util.ArrayList;import java.util.List;public class Exec {public static void main (String [] args) {System.out.println (System.getProperty ("systemProperty1")); System.out.println (System.getProperty ("systemProperty2")); for (String arg:args) {System.out.println (arg);} testGcTypeLog () } public static void testGcTypeLog () {List list = new ArrayList (); while (true) {byte [] m = costMemory (1024 / 1024 / 10); list.add (m); if (list.size () = = 90) {list.clear () }} public static byte [] costMemory (int I) {byte [] m = new byte [I]; return m;}}
The above example is to print specified system parameters and constantly request memory and then release memory, most importantly to observe and print logs.
4.0.0 cn.freemethod plugin 0.0.1-SNAPSHOT jar plugin http://maven.apache.org UTF-8 1.2.1 junit junit 4.9 test org.codehaus.mojo Exec-maven-plugin ${exec_maven_plugin_version} test exec java -DsystemProperty1=value1-DsystemProperty2=value2-XX:+PrintGCDetails-classpath cn.freemethod.plugin.Exec arg1 arg2
In the above configuration, we also bind the exec target (goal) of the exec-maven-plugin plug-in to the test phase of the default life cycle. We configure-DsystemProperty1=value1 to set the system parameters and configure-XX:+PrintGCDetails to set the jvm parameters.
You can still execute it with the following command:
Mvn test
From the image above, you can see that the system parameters, command parameters, and gc logs we set are printed.
Of course, the lifecycle can be unbound and can be configured as follows:
Org.codehaus.mojo exec-maven-plugin ${exec_maven_plugin_version} java-DsystemProperty1=value1-DsystemProperty2=value2-XX:+PrintGCDetails-classpath cn.freemethod.plugin.Exec arg1 arg2
If you configure something like this, you need to package first, and then execute exec:
Mvn clean packagemvn exec:execmaven lifecycle
Clean declaration cycle: (3 phase (phase))
Pre-clean
Clean: clean up the files generated by the last build
Post-clean
Default declaration cycle: (23 phase)
Validate
Initialize
Generate-sources
Process-sources: process the project main resource file and copy src/main/resources to classpath
Generate-resources
Process-resources
Compile: compiling src/main/java code output to classpath
Process-classes
Generate-test-sources
Process-test-sources: replace the src/test/resource directory with variables and copy it to the classpath of test
Generate-test-resources
Process-test-resources
Test-compile
Process-test-classes
Test
Prepare-package
Package
Pre-integration-test
Integeration-test
Post-integration-test
Verify
Install: install to local warehouse
Deploy
Site Lifecycle: (4 phase)
Pre-site
Site
Post-site
Site-deploy
Thank you for your reading, the above is the content of "how to use the exec-maven-plugin plug-in of maven". After the study of this article, I believe you have a deeper understanding of how to use the exec-maven-plugin plug-in of maven. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.