How do I create a hello world goal for a maven plugin?
Author: Deron Eriksson
Description: This tutorial describes how to create a hello world goal for a maven plugin.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)

Page:    1 2 >

In mavenSW, a "goal" is a unit of work that performs a particular task. A plugin is a maven artifact that is essentially a jarW file that contains a set of goals, and these goals are implemented by JavaSW "Mojo" classes. A maven plugin has a packaging of "maven-plugin". In another tutorial, we used the maven archetype plugin to create a basic maven plugin project, and we hooked this project into EclipseSW. In this tutorial, I'll create a Mojo class that implements a particular goal. We'll then install the plugin into the local maven repository so that we can use it.

The "maven-howdy-plugin" project is shown below. Like all maven projects, it contains a pom.xml file at its root. It is a maven plugin project. It also contains a "" file. This is the class that implements our goal in our plugin, as we shall see.

'maven-howdy-plugin' project in Navigator View

The pom.xml file is shown here. Notice in particular the packaging type, which is "maven-plugin". Also, notice the "maven-plugin-api" dependency. This dependency contains the various maven plugin classes that we need to have access to (such as AbstractMojo) in order to write our plugin.


<project xmlns="" xmlns:xsi=""
  <name>Howdy Plugin</name>

The HowdyMojo class is shown here. Notice the @goal javadoc annotation. This is where we specify the name of the goal that we are implementing. Since we specify "@goal howdy-world", the goal that we are implementing with the HowdyMojo class is called "howdy-world".

As we just mentioned, the HowdyMojo class is the Java class that implements this "howdy-world" goal that we just specified. Our "HowdyMojo" is a maven Mojo since it extends "AbstractMojo", which we have a reference to due to the "maven-plugin-api" dependency. The actual goal implementation code is placed in the "execute" method of the Mojo. The execute method gets a Log via getLog() and then calls the info method on it to output a "Hi there!!!" message to the console via the Log at "INFO" level.

package com.maventest;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;

 * This goal will say a message.
 * @goal howdy-world
public class HowdyMojo extends AbstractMojo {

	public void execute() throws MojoExecutionException {

		getLog().info("Hi there!!!");

(Continued on page 2)

Page:    1 2 >