Skip to content
mazl123321 edited this page Jun 10, 2013 · 7 revisions

1. Installation
    a. Maven Installation
    b. External Libraries
2. Building And Packaging
    a. Building For Thredds
3. Testing
    a. Configuration
    b. Running
4. Deploying
    a. Deploying For Sonatype
    b. Deploying For Internal Sonatype
5. Documentation
    b. Creating Javadocs

Installation

Steps for Maven installation:

  1. Download Maven
  2. Installation InstructionsMaven

Installing external, un-hosted libraries

To include any external libraries that are not hosted by a maven repo, use the following command: bash mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> -DgeneratePom=true

Where:

  • <path-to-file> the path to the file to load
  • <group-id> the group that the file should be registered under
  • <artifact-id> the artifact name for the file
  • <version> the version of the file
  • <packaging> the packaging of the file e.g. jar

Building and Packaging

Building For Thredds

To build the ncSOS-<version>.jar to use in the THREDDS server, you can use the following Maven command:

mvn clean package -DskipTests

As is implied, this will skip all of the sos tests and go directly to building a new jar. Tests need to be set up (code change) in order to properly run on each individual computer and broken tests will prevent Maven from fully building the target jar. The tests also can take a long time to run (close to 10 minutes), so it is recommended that you run the tests individually from packaging the jar. See below for how to setup the tests to run on a computer.

Testing

Configuration

See Test Setup

Running Tests

To run the tests you can run the Maven command below

mvn test

If you want to run a single test, for example SOSgetCapsTest.java, use the following Maven instruction

mvn test -Dtest=SOSgetCapsTest.java

Another useful option is the -X option which will print out debug logging. If this option is used, it is recommended to pipe the output to a text file (windows example):

mvn test -X > test_output.txt 2>&1

(The 2>&1 pipes stderr to stdout, which will be printed to the file).

In addition to the output of the tests, surefire creates reports in the /target/surefire-reports folder that will hold specific failures and errors for each test run.

Deploying

Deploying To Sonatype

Note: You must have a valid Sonatype JIRA account in order to deploy to the Sonatype repo: https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-2.Signup

You must also edit your Maven settings.xml as detailed here: https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-7a.1.POMandsettingsconfig

ncSOS's pom is setup to be a child of the sonatype oss pom. This ensures that when deployed, ncSOS will be uploaded to the sonatype servers as a snapshot (or staged for release).

To deploy ncSOS to sonatype use the following Maven instruction:

mvn clean deploy

By default, 'deploy' will upload the project to the server to be staged for release. If you want to upload a snapshot of the project you need to edit the version of the project in pom.xml: xml <version>0.1a</version>

By adding a -SNAPSHOT to the version string, sonatype will treat the upload as such and will put it in the snapshot repo. The above, as a snapshot, would look: xml <version>0.1a-SNAPSHOT</version>

Deploying To Internal Sonatype

To configure a Maven project to publish artifacts to Nexus, you'll need to add a distributionManagement element to your project's pom.xml. Here's an example of a distributionManagement element that contains the appropriate configuration to deploy snapshots and releases to a server running on your.server.com port 8081:

```xml
deployment Internal Releases http://your.server.com:8081/nexus/content/repositories/releases/ deployment Internal Releases http://your.server.com:8081/nexus/content/repositories/snapshots/ ```

If your Nexus server requires authentication, you will also need to place your credentials in ~/.m2/settings.xml in a servers element. Here's a sample servers element using the default username and password for the deployment user:

```xml
deployment deployment deployment123 ``` Once you've configured your project's pom.xml and your Maven Settings, you can deploy your project with "mvn deploy" which will execute the build up to the deploy phase. When you run a deploy with a project that has a snapshot version, Maven will deploy to the repository defined in snapshotRepository, and when you run a build with a project that has a release version it will deploy to the repository defined in the repository element.

Documentation

Generating Javadocs

Generating javadocs with maven is straightforward. Make sure that the pom.xml has the following set of tags defined: xml <reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.4</version> <configuration> <aggregate>true</aggregate> <quiet>true</quiet> </configuration> </plugin> </plugins> </reporting>

With the preceeding in place then simply run mvn javadoc:javadoc to generate the javadocs for the project. (It is recommended you 'clean' before generating the javadocs).

Clone this wiki locally