Sprig Maven

  • Maven is a project management tool

  • ANT is also a build tool which is similar to Maven and it is a default build tool in Intellij IDEA,Netbeans,Eclips

  • Replace the build tool to maven.

  • Maven has a common folder structure.Hence any developer can easily identify the project.

  • Maven can create documentation by checking the source code of the project.Hence source code should be correctly formatted.

  • Source code read by doc comments

  • Maven is a collection of dependency management tool and document development tool

  • All the dependencies are download into the home directory as common repository not for each project.


  • Plugins are created by set of goals.

  • Maven is created by set of pulgins.

  • Create a Project :
    mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart -DgroupId=com.mycompany.app -DartifactId=my-app

  • Execute a goal : mvn :
    • EX : mvn compiler : compile

  • Maven life Cycle
    1. Clean(clear all created artifacts and rebuild the project)
    2. Default(create project)
    3. Site(Use to create websites)

  • can compile one or more life cycles together.("mvn clean defualt site")

  • Life cycles have one or more phases.

  • Clean
    1. pre-clean
    2. post-clean
    3. clean

  • Default
    1. validate (check folder structure)
    2. compile (compile the code)
    3. test (compile test cases)
    4. package (build artifacts)
    5. verify (check integration tests)
    6. install (install project as a dependency in a local repository)
    7. deploy (send the project to the remote repository from local rep)

  • Site
    1. pre-site
    2. post-site
    3. site
    4. site deploy

  • Phase is created by set of goals from different set of plugins.

  • Archetype is a project template in maven.
      Examples for archetypes :
    1. maven-archetype-quickstart
    2. maven-archetype-webapp

  • Project structure

  • POM (Project Object Model)
    • ‘pom.xml’ contains the Project Object Model for the project
    • POM contains every important piece of information about the project.
      com.mycompany.app my-app jar 1.0-SNAPSHOT Maven Quick Start Archetype
    • Generate IDE specific project descriptor
      mvn idea:idea mvn eclipse:eclipse


  • Dependency Management
    • type
      Packaging type of the project (jar, war, ear)
    • version
      Version of the project. “SNAPSHOT”: A beta version in changing phase Downloaded when a maven phase is executed in a timely manner
    • optional
      Marks as optional when the project itself is a dependency./li>
    • scope
      Classpath of the task (compiling, runtime or test execution) Different scopes are as following.
      • “compile”
        Default scope. Dependencies are available in all classpaths. Propagated to dependent projects
      • “test”
        Only available for test compilation and execution. These are not transitive

      • “provided”
        Expect the JDK or the container to provide at runtime.

      • “runtime”
        Not needed for compilation but for runtime and test execution.

      • “system”
        Similar to provided but need to specify the JAR file.
    • systemPath
      Used when dependency scope is system. Example: ${java.home}/lib

  • Plugins are used to customise the build for a project.

  • Maven Jar Plugin
    • Used to set the manifest for the JAR file.
  • Modules
    • Can contain a project with multiple modules.
    • Dependency modules are always build before dependent modules.
    • Have to mention the parent information in the sub module
  • Property File
    • All project resources are maintained in separate resource directories inside main.
      src -> main -> resources
      src -> test -> resources
    • Most of the times, property files which contain application configuration are stored in these locations.
    • Can also be explicitly mentioned also in the resources section of the POM.

  • Comments

    Popular posts from this blog