You are on page 1of 3

***What is plugin?

A plugin provides a set of goals that can be executed to perform a task. There are
Maven plugins for building, testing, source control management, running a web
server, generating
Eclipse project files, etc. Some basic plugins are included in every project by
default.

**** What is phase ?

Maven build lifecycle goes through a set of stages, they are called build phases.
For example, the default lifecycle is made up of the following phases.

validate
compile
test
package
verify
install
deploy

The build phases will be executed sequentially. When we run a maven build command,
we specify the phase to be executed. Any maven build phases that come before the
specified phase is also
executed. For example, if we run mvn package then it will execute validate,
compile, test, and package phases of the project.

***What is goal?

Goal is used to represent a specific task that contributes to the building and
managing of a project. It may be bound to zero or more build phases. The order of
execution depends on the order in
which the goal(s) and the build phase(s) are invoked. We can write our own plugins
with goals or use those provide by Maven.

Each phase is a sequence of goals and each goal is responsible for a specific task.
When we run a phase, all goals bound to this phase are executed in order.

Here are some of the phases and default goals bound to them:

--- compiler:compile - the compile goal from the compiler plugin is bound to
the compile phase
--- install:install - It is bound to the install phase
--- jar:jar and war:war is bound to the package phase

Here is an example to execute the dependency tree goal from the command line. It’s
not part of any build phases.

mvn dependency:tree

Note: We can also configure goals in the pom.xml file using the plugins element.
This is mostly required when you have created a custom plugin and want to execute
any specific goal for a
build phase.

*** How to create different types of Maven Projects using Command Prompt

Interactive Mode - Interactive mode means It will take input from the user (Its
more of choice based)
Batch Mode - batch mode means no need to type anything from keyboard, all inputs
will be given directly as a command only.

jar [java archive] and war [web application archive]

****Interactive mode [maven-archetype-quickstart]

mvn archetype:generate

-- choose a specific archetype and provide values then change the directory [1924]

mvn validate
mvn compile
mvn test
mvn package
mvn verify
mvn install

-- Run the jave file using

java -classpath target\jarfilename com.klef.jfsd.App

****Interactive mode [maven-archetype-webapp]

mvn archetype:generate

-- choose a specific archetype and provide values then change the directory [1929]

mvn install

-- Run the webapplication using

place war file in webapp folder of tomcat and run the server

****Batch Mode

mvn archetype:generate -DgroupId=com.klef.jfsd -DartifactId=samplejavaproject -


DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

if <build> tag is already there, include only <plugins> tag code

mvn archetype:generate -DgroupId=com.klef.jfsd -DartifactId=samplewebproject -


DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

if <build> tag is already there, include only <plugins> tag code

mvn clean install [This command will delete previous target if you have in the
maven project and It will perform all the phases upto install]

****Last two commands

mvn site - This will create project documentation, you can find the same in target
folder then open site folder then open index.html
mvn dependency:tree - This will show all the dependencies from pom.xml file.

Open pom.xml of that maven web project then go to <build> tag then go to
<pluginManagement> tag then go to <plugins> tag then include below code with in
<plugins> tag

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.3.0</version>
</plugin>

Save pom.xml file then run mvn site command again :)

If you don't find <pluginManagement> tag and <plugins> tag then

in the <build> tag , include below code

<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.3.0</version>
</plugin>

</plugins>

You might also like