The contents of this document are a work in progress

Preparing the web application project to use Plexus

We will create a very basic web application project first and then gradually evolve it to demonstrate how Plexus can be embedded.

To create a web application skeleton:

  1. Open the command prompt/terminal window.
  2. Change directory to where you want to create your web application project.
  3. Run the following Maven command
    mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes \
        -DarchetypeArtifactId=maven-archetype-webapp \
        -DarchetypeVersion=1.0-alpha-4-SNAPSHOT  \
        -DgroupId=org.codehaus.plexus.examples \
        -DartifactId=plexus-example-webapp  \
        -DpackageName=org.codehaus.plexus.tutorial \
        -Dpackaging=war \
        -DremoteRepositories=http://people.apache.org/repo/m2-snapshot-repository/

Archetype creation options are explained here:

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

For more information on Maven Archetypes please refer to this resource on the Maven website.

A web application project should have been created now at the location where you ran the archetype:create command.

Locate the pom.xml under the created project, the contents of the POM should be as below:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.codehaus.plexus.examples</groupId>
  <artifactId>plexus-example-webapp</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Maven Webapp Archetype</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>plexus-example-webapp</finalName>
  </build>
</project>

Updating the POM

Before we can embed Plexus in our web application we need to make the JAR library that contains the Plexus Embedder available to our project. We do this by introducing required <dependency> elements in the project's pom.xml.

The updated pom.xml (along with some other updates) looks as below:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <parent>
    <artifactId>plexus-examples</artifactId>
    <groupId>org.codehaus.plexus.examples</groupId>
    <version>1-SNAPSHOT</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.codehaus.plexus.examples</groupId>
  <artifactId>plexus-example-webapp</artifactId>
  <packaging>war</packaging>
  <name>Plexus Web Application Example</name>
  <version>1.0-SNAPSHOT</version>
  <url>http://maven.apache.org</url>
  <build>
    <finalName>plexus-example-webapp</finalName>
  </build>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <!-- Added for embedding plexus -->
    <dependency>
      <groupId>org.codehaus.plexus</groupId>
      <artifactId>plexus-servlet</artifactId>
      <version>1.0-beta-5</version>
    </dependency>
    <dependency>
      <groupId>org.codehaus.plexus</groupId>
      <artifactId>plexus-container-default</artifactId>
      <version>1.0-alpha-10</version>
    </dependency>
  </dependencies>
</project>

Generate a Project for your IDE.

For Eclipse.

  1. Change directory to the newly created directory 'plexus-example-webapp'
  2. Run the following command from command prompt to generate Eclipse project setting files.
     (for WTP 0.7)
     E:\plexus\plexus-examples\plexus-example-webapp>mvn eclipse:eclipse 
     (for WTP 1.0 or higher)
     E:\plexus\plexus-examples\plexus-example-webapp>mvn eclipse:eclipse -Dwtpversion=1.0

Eclipse project files should get generated succesfully at this point. If there were any unsatisfied dependencies, 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.