The contents of this document are a work in progress

Overview

The chapter gets you to jump start into Plexus Component development. While a scan through of 'Concepts' would be helpful, it is not really required.

Where ever deemed neccessary cross-references are provided to make it easy for a new developer to reference the required material.

Pre-requisites

The tutorial assumes you have Maven 2.0.x+ setup and have an internet connection and are able to download required Maven artifacts from online repositories.

For the purpose of this tutorial we will develop a Plexus Website Monitor component.

Lets get started!

Create that skeleton!

Plexus has some archetypes available that can make initial project setups a breeze. We use one such archetype for our Plexus component here. From the command prompt, change directory to the location where you wish to set up the new Plexus Component project. Run the following command from the command line to setup an initial project structure


 mvn archetype:create -DarchetypeGroupId=org.codehaus.plexus -DarchetypeArtifactId=plexus-archetype-component-simple -DarchetypeVersion=1.0-alpha-1-SNAPSHOT -DgroupId=org.codehaus.plexus -DartifactId=plexus-website-monitor-component  -DpackageName=org.codehaus.plexus.tutorial -Dpackaging=jar -DremoteRepositories=http://snapshots.repository.codehaus.org/

Cool! At this point you've created a basic project structure that should give you a jump-start into development.

Archetype creation options explained

More info on archetype creation and usage can be found here on the Maven website.

The following table explains the options that we used above.

Commandline Option Description Required
-DarchetypeGroupId "groupId" for the archetype we want to use Yes
-DarchetypeArtifact "artifactId" for the archetype we want to use Yes
-DarchetypeVersion "version" for the archetype we want to use Yes
-DgroupId "groupId" for the project to be generated Yes
-DartifactId "artifactId" for the project to be generated Yes
-DpackageName Base package name to be use for any Java sources being copied over No
-Dpackaging Packaging to be used for the created project No
-DremoteRepositories Comma-separated list of repositories to lookup to retrieve archetype No

Generate a Project for your IDE.

For Eclipse.

  1. Change directory to the newly created directory 'plexus-website-monitor-component'
  2. Open up pom.xml and review the handful of dependencies setup there for version changes.
  • As of this writing Plexus Snapshots were not being published to the Codehaus snapshots repository. Hopefully this should get resolved quickly.
    1. Run the following command from command prompt to generate Eclipse project setting files.
       E:\workspaces\plexus-docs\plexus-website-monitor-component>mvn eclipse:eclipse

Eclipse project files should get generated succesfully at this point. If there were any unsatisfied dependencies (due to 2-1-3), update version for dependencies in pom.xml to an available release version.

  1. Fire up Eclipse and import the generated project into an Eclipse Workspace.

Now, let's quickly recap the resources we see in our Eclipse project.

Eclipse Package Explorer View of our import Plexus Component project.

That concludes the preparation for our component project, we are all set to get our hands dirty with our first Plexus component.

If you have a developer's itch and want to see if there is something we can do with the minimal project setup by the archetype for us - well, good news! Navigate your way through to the "HelloWorldTest" class (selected in the image above). Right click on it and choose "Run As > JUnit Test" and see for yourself. eeeks.....our unit test failed!! But fear not, for we come back to Component testing in a later chapter, so stay put!

The project resources that we setup so far can be downloaded from this link here: