Tuesday, March 6, 2012

Maven

To create a project
mvn archetype:generate -DgroupId=com.vis.rest -DartifactId=MobileSpoc.rest -DarchetypeArtifactId=maven-archetype-quickstart  -DinteractiveMode=false


Creates a simple project named "MobileSpoc.rest" and a package named "com.vis.app"

If you have just installed Maven, it may take a while on the first run. This is because Maven is downloading the most recent artifacts (plugin jars and other files) into your local repository. You may also need to execute the command a couple of times before it succeeds. This is because the remote server may time out before your downloads are complete. Don't worry, there are ways to fix that.

pom.xml
The pom.xml file is the core of a project's configuration in Maven. It is a single configuration file that contains the majority of information required to build a project in just the way you want.

Changing Target Java Version
1) By default, Maven attempts to build for compatibility with JDK 1.3 
2) Using Jersey requires annotations, which aren't supported until JDK 1.5
3) Maven must be instructed to target a different JDK version via the POM file

Build the project
 mvn package
Unlike the first command executed (archetype:generate) you may notice 
the second is simply a single word - package. Rather than a goal, this is a phase.
A phase is a step in the build lifecycle,
 which is an ordered sequence of phases. When a phase is given, Maven 
will execute every phase in the sequence up to and including the one 
defined. For example, if we execute the compile phase, the phases that actually get executed are:
  1. validate
  2. generate-sources
  3. process-sources
  4. generate-resources
  5. process-resources
  6. compile
You may test the newly compiled and packaged JAR with the following command:
java -cp target/my-app-1.0-SNAPSHOT.jar com.vis.app.App

 
Maven Phases
  • validate: validate the project is correct and all necessary information is available
  • compile: compile the source code of the project
  • test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package: take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test: process and deploy the package if necessary into an environment where integration tests can be run
  • verify: run any checks to verify the package is valid and meets quality criteria
  • install: install the package into the local repository, for use as a dependency in other projects locally
  • deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

Creating a sample Java EE 6 Blog Application with JPA, EJB, CDI, JSF and Primefaces on GlassFish

http://www.hascode.com/2011/02/creating-a-sample-java-ee-6-blog-application-with-jpa-ejb-cdi-jsf-and-primefaces-on-glassfish/ 

  
 
References
http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html 

No comments:

Post a Comment