Maven study summary

Maven features

  • manage multiple jars
  • dependencies and versions
  • project structure
  • build, publish and deploy

Details in pom.xml

  1. Archetype: project structure/template/type. for example:jee/spring/hibernate
  2. Group id: package(name) like
  3. Artifact id : project name, which is under Gourp id
  4. Packaging: build type , for example: jar/ear/war

Maven Phases

  1. validate
  2. compile
  3. test
  4. package
  5. install: to local maven repository
  6. deploy: to remote maven repository

Other stuff

  • mvn clean: clear all the .class/distributions that generated bofore
  • plugin for compiler is customizable: could be 1.4/1.5…etc
  • add Jetty plugin and use mvn jetty:run to run project in jetty directly. use <scanIntervalSeconds> for hot deploy in <build><configuration>
    Same thing as tomcat, use mvn tomcat:run for app to run in tomcat
  • maven eclipse plugin: in a maven project, use mvn eclipse:ecplise to make it available for eclipse import. it generates the .project file that eclipse would need.

There are 6 scopes available:

  • compile
    This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.
  • provided
    This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
  • runtime
    This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.
  • test
    This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.
  • system
    This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.
  • import (only available in Maven 2.0.9 or later)
    This scope is only used on a dependency of type pom in the <dependencyManagement> section. It indicates that the specified POM should be replaced with the dependencies in that POM’s <dependencyManagement> section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.

the variable in eclipse build option is for defining global pairs of configuration path. for example point the M2_REPO to local customized folder.

THIS is a very good tutorial for Maven!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s