Skip to content

how-you-doing/hello-maven

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hello-maven

Maven is a build tool, mainly used to build and manage java projects.

1. First maven project

2. pom.xml

  • The core of mvn project is pom.xml (pom refers to Project Object Model)
  • It is a single configuration file that contains the majority of information required to build a project in just the way you want
  • It has 3 important elements
    1. groupId- indicates the unique identifier of the organization or group
    2. artifactId- indicates the unique base name of the primary artifact being generated by this project. For example JAR name
    3. version- version of the project

3. Maven Lifecycles

  • validate- validates the maven project that everything is correct and all the 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 to 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
  • clean- clean up artifacts created by prior builds
  • site- generates site documentation for this project

4. Execution

  • mvn clean- will clear all the artificates present in the project folder

    • clears target directory present in the project folder
  • mvn compile- compiles all the source codes of the project

    • For example, .java files present in the main and test
  • mvn test- executes the test cases present in the project

    • As a result, you will get the status something like this Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
  • mvn package- takes all the compiled source and package them as a jar

    • JAR can be found inside target directory, ex: /home/${USER}/workspace/hello-maven/target/hello-maven-1.0-SNAPSHOT.jar
  • mvn install- copy the generates JAR into local repo, so that other projects can make use of this work

    • your JAR will be moved to /home/${USER}/.m2/repository/com/hod/hello-maven/1.0-SNAPSHOT/hello-maven-1.0-SNAPSHOT.jar

Note

We can execute multiple phases or goals in a single line. For example,

mvn clean compile package

References

  1. https-//maven.apache.org/guides/getting-started/maven-in-five-minutes.html
  2. https://www.journaldev.com/33645/maven-commands-options-cheat-sheet

Releases

No releases published

Packages

No packages published

Languages