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.

Extending <strong>Apache</strong> <strong>Maven</strong><br />

200<br />

<br />

<br />

<br />

<br />

<br />

5. The next step is to build and install the project into your <strong>Maven</strong> local repository:<br />

$ mvn install<br />

6. On build success, you can now execute the plugin from the command line:<br />

$ mvn net.srirangan.packt.maven:maven-plugant-plugin:hello<br />

How it works...<br />

hello.mojos.xml contains the definition and configuration of the Mojo. It is the one that<br />

associates the hello goal with the hello.build.xml Ant build script.<br />

The project POM file shows a dependency on Ant itself (of course!). It also makes use of<br />

maven-plugin-plugin with a dependency on maven-plugin-tools-ant.<br />

These together allow <strong>Maven</strong> plugins to be written in Ant and located in the src folder to be<br />

discovered, packaged, and installed.<br />

If you look at your local repository, you will find that the Ant plugin has been converted into<br />

an artifact (.jar) at repository/net/srirangan/packt/maven/maven-plugantplugin/1.0-SNAPSHOT/maven-plugant-plugin-1.0-SNAPSHOT.jar.<br />

Creating a <strong>Maven</strong> plugin using JRuby<br />

JRuby is a 100 percent pure Java implementation of the popular scripting and programming<br />

language–Ruby. JRuby shares a number of features from Ruby like being dynamic and<br />

reflective. To its audience, JRuby/Ruby is close to being the best thing since sliced bread.<br />

Syntactically, JRuby/Ruby makes it easy to get started and to quickly accomplish programming<br />

tasks that would otherwise take you a while with Java.<br />

But since JRuby is based on the Java Virtual Machine, it compiles into bytecode for JVM and<br />

can interact seamlessly with existing Java infrastructure, much like Groovy and Scala.<br />

Getting ready<br />

For this recipe, you need <strong>Apache</strong> <strong>Maven</strong> 3 installed and set up correctly. You also need to<br />

be familiar with <strong>Maven</strong> concepts such as archetypes, project co-ordinates, dependencies,<br />

and so on.<br />

Additionally, you need to be familiar with programming/scripting in JRuby/Ruby.

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

Saved successfully!

Ooh no, something went wrong!