17.08.2016 Views

Apache Maven 3 Cookbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9<br />

/**<br />

* @goal wassup<br />

*/<br />

public class MyMojo2 extends AbstractMojo {<br />

public void execute() throws MojoExecutionException {<br />

getLog().info("Wassup");<br />

}<br />

}<br />

2. The plugin project can now be built, and plugin goals executed as follows:<br />

$ mvn install<br />

$ mvn plug101:wassup<br />

3. To enable your <strong>Apache</strong> <strong>Maven</strong> plugin to be externally configurable, you need to make<br />

use of the parameter annotation (@parameter) in the MOJO while defining it, as<br />

shown in the following code:<br />

import java.util.Properties;<br />

/**<br />

* @parameter<br />

*/<br />

private Properties myProperties;<br />

These are not typical Java 6 annotations and you need to<br />

encapsulate them in the /** **/ comments tag.<br />

4. Our next step is to modify the project's POM file to include the configuration for<br />

myProperties. You will need to add a configuration element to your existing<br />

structure, as shown in the following code:<br />

<br />

<br />

<br />

...<br />

<br />

<br />

<br />

name<br />

Sri<br />

<br />

<br />

age<br />

26<br />

<br />

193

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!