Skip to content

Maven Datasource Archetype

ksuderman edited this page Nov 27, 2013 · 3 revisions

Project creation with Maven.

Warning: This archetype is out of data. A new version will be deployed shortly

This document describes how to set up a simple web service project using the Maven archetype deployed to the ANC's Maven repository. A Maven archetype is simply an template Maven project with some simple Java classes that can be used as a starting point to implement a web service. In this example we create a DataSource web service, but it is possible to create an archetype for each available service type.

Requirements

  1. Maven 3.x. Maven 2.x will likely work as well, but has not been tested.
  2. Eclipse. Any IDE can be used for Java development with Maven, however these instructions assume Eclipse is being used. The procedure will be similar with other IDEs.

The ANC Maven Repositories

To use of the DataSource archetype and other Maven artifacts you will need to add the following repositories to your ~/.m2/settings.xml file:

<repositories>
    <repository>
        <id>anc-releases</id>
        <url>http://www.anc.org:8080/nexus/content/repositories/releases/</url>
        <releases><enabled>true</enabled></releases>
        <snapshots><enabled>false</enabled></snapshots>
    </repository>
    <repository>
        <id>anc-snapshots</id>
        <url>http://www.anc.org:8080/nexus/content/repositories/snapshots/</url>
        <releases><enabled>false</enabled></releases>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
    </repository>
    ...
</repositories>

If you are new to Maven you may want to simply use the ANC's default settings.xml file. The ANC's Nexus repository mirrors Maven Central, and the Apache and Codehaus snapshot repositories so it should find everything you need. This file does not need to be edited and can be copied verbatim to your ~/.m2 directory (if the ~/.m2 directory doesn't exist simply create it).

Creating a project with the Maven Archetype

Before using a Maven archetype for the first time it needs to be installed into Eclipse. This is a one-time procedure and is done during the New Project setup. Once the archetype is installed new projects can be created without having to add the archetype.

  1. Open Eclipse and create a new Project: File -> New -> Project.
  2. In the New Project dialog enter the text Maven in the Wizards field, select Maven Project and click the Next button.
    New project
  3. Nothing needs to be changed in the Select project name and location dialog so click the Next button.
  4. In the Select an Archetype dialog click the Add Archetype… button. Enter the following information into the Add Archetype dialog
    Archetype Group Id: org.anc.lapps.maven
    Archetype Artifact Id: rawdatasource-archetype
    Archetype Version: 1.0.0
    Repository URL: http://www.anc.org:8080/content/repositories/releases
    ![Add archetype](http://www.anc.org/images/lapps-wiki/AddArchetype2.png)
    **Note** The above step only need to be performed the first time an archetype is used.
  5. In the Select an Archetype dialog enter the text lapps in the Filter field, select the rawdatasource-archetype, and click the Next button.
    Select archetype
  6. In the Select archetype parameters dialog you can enter any values you like for the groupId, artifactId, and version number. Follow the naming conventions, if any, established by your institution.Archetype parameters
    Tip Maven will use the specified artifactId as the project directory name. Therefore I like to use whatever directory name I want as the artifactId and then edit the pom.xml file afterwards to change the artifactId to what I actually want it to be.
  7. Click the Finish button.

At this point Maven will have generated a complete project that implements the RawDataSource api. If you build the project you will get a war file that can be deployed to Tomcat (although all the example service does is return "Unsupported operation" errors).