Getting Started with Maven | Java Application Development | Plugin
The project you created could be built and bundled into a Jar file with Maven commands. However, this Jar file is somewhat inconvenient to handle. You have to specify the Jar file with -classpath and run the main class. Many people may wonder, “Can this be made easier to run?” It can. To do that, however, you need to know how to use “plugins.”
Maven adds many features through “plugins.” Program execution is implemented by a plugin called “exec-maven-plugin.” By adding configuration information for this plugin to pom.xml, you can run the program.
A plugin is included inside the <project> tag in pom.xml in the following form. This example is for a build plugin.
<build>
<plugins>
<plugin> ... omitted ... </plugin>
</plugins>
</build>
<build> is used to write build-related settings, and <plugins> gathers plugin configuration information. Inside it, the <plugin> tag is used to collect settings for a specific plugin.
Many plugins are available besides this one. In fact, some features already explained are implemented with plugins. For example, the mvn compile command is implemented by a plugin called maven-compiler-plugin. Also, mvn package is implemented by a plugin called maven-jar-plugin.
In other words, the goals used in Maven, such as compile and package, are all built in as plugins. You do not need to download these with <dependency> tags. Some can be used as standard features, and if they are not present, they are downloaded as needed. You do not need to prepare a separate <dependency> tag.
The <plugin> Tag
The <plugin> tag, which writes configuration information for a plugin, must contain the information required for that plugin.
The minimum tags are generally as follows.
<plugin>
<groupId>Group ID</groupId>
<artifactId>Artifact ID</artifactId>
<version>Version</version>
<configuration>
...... configuration information ......
</configuration>
</plugin>
You should now be familiar with values such as group ID, artifact ID, and version. These values specify the plugin program to use. The <configuration> tag after that prepares the information needed to use the plugin. The contents written there differ depending on the plugin, and in some cases it is not needed.