Maven Information

From Kb

Jump to: navigation, search

Contact Article Author | Blog of Article Author | FirstPartners.net Home | LinkedIn profile of Author

Contents

See Also

  1. Appfuse Information
  2. Deploying to Weblogic using Maven
  3. Eclipse Setup - M2Eclipse Plugin
  4. Maven and Ant integration
  5. Red Piranha Open Source Project
  6. Spring Framework

Maven Setup

Maven Web Access with a Proxy Server

  • Change the settings.xml file (under maven/conf directory) to
<proxies>
    <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>host-ip</host>
      <port>host-port</port>
    </proxy>
  </proxies>

Maven and Eclipse

  1. Eclipse Maven Plugin (from CodeHaus Site): http://m2eclipse.codehaus.org/
  2. Install in usual manner (online via eclipse update, or download all locally)
  3. Getting Started with Maven Guide: http://maven.apache.org/guides/index.html
  4. To generate Eclipse project files - mvn eclipse:clean eclipse:eclipse
    1. For sub projects (core and web) - open these as normal java projects
    2. For main projects (/) - open this a general project - otherwise get a circular build

Creating a new project using Maven

  1. Create new Project folder
  2. Select the Maven Archetype (project template) that you wish to use
    1. Simple list of Maven Archetypes (and tutorial) - Check out the examples on the left hand side.
    2. Apache List of Standard Archetypes - you made need to include this repository in your pom to access these.
    3. CodeHaus List (includes Appfuse and other non-apache templates)
    4. Worth Googling , as there are many others to choose from
  3. Create the archetype from the command line by issuing the following Maven command
mvn archetype:create \
   -DgroupId=<your group> \
   -DartifactId=<your artifact> \
   -DarchetypeArtifactId=<wanted artifact> \
   -DarchetypeGroupId=<wanted artifact group>

e.g. for creating a simple webapp

mvn archetype:create \
  -DgroupId=net.firstpartners.rp \
  -DartifactId=test-core-app \
  -DarchetypeArtifactId=maven-archetype-webapp \

Maven Plugins

Using Maven Day to Day

Useful Maven Commands

mvn help:describe -DgroupId=org.apache.maven.plugins -DartifactId=maven-compiler-plugin -Dfull=true
  • Find out what the current pom (e.g. if it inherits from the super pom or main project)
mvn help:effective-pom
  • Run Standard Command but with additional info (e.g. StackTrace and full debug loggin)
mvn -e -X test


  • Run a single test:
    • mvn test -Dtest=SomeNameOfTest
    • mvn test -Dtest=SomeNameOf*
  • Show testing errors in console
    • add -Dsurefire.useFile=false to the mvn test command.
  • Maven clean build from root of project
    • mvn clean install - Installs all needed Libs (as listed in the pom.xml) and the core.jar file into the maven repository
    • mvn clean package - Builds all intermediate jars , and the final war / ear file

Maven and Tomcat

Maven running in process Tomcat

Run Tomcat via Maven

  1. Add Maven 2 Tomcat Plugin to the project Pom (or be online so that Maven can download it automatically)
  2. mvn tomcat:deploy to deploy or tomcat:run to start tomcat (no deployment)
    1. Options as to how often it scans for differences.
    2. Other options are availabel - see linked page
    3. May need to do a mvn install on the project as the war being deployed is pulled from your local re

Maven Deployment to (Standard) Tomcat

Hack , but it works. Put the following in a .bat file

net stop "apache tomcat"
copy Location_of_war_file\webapp-1.0-SNAPSHOT.war C:\software\Tomcat55\webapps\DEPLOYNAME.war
net start "apache tomcat"

Normally used (from within the web project) as part of the following command:

mvn -o package -Dmaven.test.skip=true ; ../dp.bat

Maven Properties

To pass in from command line mvn commandname -Dpropertyname=value

Can also edit 'properties' section in main pom.xml

Guide (based on 1.x) : http://maven.apache.org/maven-1.x/reference/properties.html

How to override : http://maven.apache.org/maven-1.x/reference/properties.html

e.g. To turn off maven tests

  1. Create a file build.properties
  2. Add an entry maven.test.skip=true

or pass on the command line as -D Switch

e.g Download Sources

  1. -DdownloadSources=true e.g.
  2. mvn clean package -DdownloadSources=true

(gives more info if you need to track through the classes of the libs that you use)

Maven Deployment Profiles and Lifecycle

Deployment Profiles: http://maven.apache.org/guides/introduction/introduction-to-profiles.html

Maven Build Lifecycle :http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

Project Release Using Maven

Pom.xml

Using Java 5 with Maven

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<sourcex>1.5</sourcex> <!-- remove x - only to allow correct display here -->
<target>1.5</target>
</configuration>
</plugin>

Extending Maven

Creating your own Maven Archtype

Personal tools