Maven Information
From Kb
Contact Article Author | Blog of Article Author | FirstPartners.net Home | LinkedIn profile of Author
Contents |
See Also
- Appfuse Information
- Deploying to Weblogic using Maven
- Eclipse Setup - M2Eclipse Plugin
- Maven and Ant integration
- Red Piranha Open Source Project
- Spring Framework
Maven Setup
- Download Maven from http://maven.apache.org/download.html
- Unzip file to location such as c:\software\maven
- Follow the instructions in Readme.txt (i.e. add MVN to Path)
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
- Eclipse Maven Plugin (from CodeHaus Site): http://m2eclipse.codehaus.org/
- Install in usual manner (online via eclipse update, or download all locally)
- Getting Started with Maven Guide: http://maven.apache.org/guides/index.html
- To generate Eclipse project files - mvn eclipse:clean eclipse:eclipse
- For sub projects (core and web) - open these as normal java projects
- For main projects (/) - open this a general project - otherwise get a circular build
Creating a new project using Maven
- Create new Project folder
- Select the Maven Archetype (project template) that you wish to use
- Simple list of Maven Archetypes (and tutorial) - Check out the examples on the left hand side.
- Apache List of Standard Archetypes - you made need to include this repository in your pom to access these.
- CodeHaus List (includes Appfuse and other non-apache templates)
- Worth Googling , as there are many others to choose from
- 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
- DbUnit plugin (standard as part of appfuse): http://maven-plugins.sourceforge.net/maven-dbunit-plugin/
Using Maven Day to Day
Useful Maven Commands
- Maven Help Commands
- http://maven.apache.org/plugins/maven-help-plugin/usage.html
- Describe a maven plugin / command / artifact (in this case the compiler plugin)
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
- Maven Command Line Reference : http://maven.apache.org/maven-1.x/reference/command-line.html
- 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
- Add Maven 2 Tomcat Plugin to the project Pom (or be online so that Maven can download it automatically)
- mvn tomcat:deploy to deploy or tomcat:run to start tomcat (no deployment)
- Options as to how often it scans for differences.
- Other options are availabel - see linked page
- 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
- Create a file build.properties
- Add an entry maven.test.skip=true
or pass on the command line as -D Switch
e.g Download Sources
- -DdownloadSources=true e.g.
- 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
- (this page gives information on creating your own Maven Architype or project template)

