Plan du site  
pixel
pixel

Articles - Étudiants SUPINFO

Use Maven for managing project in an easier way

Par Jingwei BAI Publié le 15/01/2019 à 18:05:50 Noter cet article:
(0 votes)
Avis favorable du comité de lecture

1.1 Preview

In this article, you will learn what is maven and how does it help us to optimize the deployment in the workplace. There is the structure of this article which will help you to have a first look of it.

1.1 Preview

1.2 What is Maven ?

1.2.1 Define Maven

1.2.2 What is Maven Repository ?

1.3 Why do we use Maven ?

1.3.1 The past years we do not have Maven.

1.3.2 Maven makes directory structure standard

1.3.3 pom.xml - the core of Maven

1.3.4 Advantages

1.3.5 How to use Maven?

1.4 Conclusion

1.5 Bibliography

1.2 What is Maven?

1.2.1 Define Maven

Maven is an open source project management tool written in pure Java. Maven uses a concept called Project Object Model (POM) to manage projects.

POM refers to the engineering object model, that is, the project is managed as an object, and all project configuration information is defined in a file called POM.xml.

Through this file Maven can manage the entire life cycle of the project, including cleanup, compilation, testing, reporting, packaging war, deployment and more.

1.2.2 What is Maven repository?

The Maven repository is used to store all the Jar packages managed by Maven. Divided into: local repository and central repository.

  • Local repository: The Jar package repository for Maven.

  • Central repository: A remote repository provided by Maven.

When the project is compiled, Maven will look for the Jar package required by the project from the local repository at first. If the local repository does not exist, then it will go to the central repository of Maven to download the required Jar package.

1.3 Why do we use Maven?

1.3.1 The past years we do not have Maven.

If we build a project, we need to use a lot of third-party libraries. For example, to write a Web project using Spring, you need to introduce a large number of jar packages.

The number of Jars in a project often makes us stunned and messy, and the relationship between Jar packages is usually complicated. A Jar package often refers to other Jar packages. The lack of any Jar package will cause the project to fail to compile.

In the past, when developing projects, programmers often need to spend more time on the environment of checking the Jar package, which is especially complex to manage. One less Jar package and one more Jar package will often report some confusing information errors.

Maven is a tool to help us to build projects automatically. We just need to tell Maven which Jar packages we need. It will help us download all the Jars. What is more, maven will greatly improve the development efficiency.

1.3.2 Maven makes directory structure standard

1.3.3 pom.xml - the core of Maven

Pom.xml is the core of Maven. Which Jar package you need for your project, you can configure in pom.xml. When the project is compiled, Maven reads the file and downloads the corresponding Jar package from the repository.

Let's talk about the POM configuration details. It's actually simple to learn. Take a look at the pom.xml:

Maven's coordinates GAV (groupId, artifactId, version) are configured here, and these are required.

The special thing is that the packaging here is pom. All packages with submodules are packaged as pom. If the packaging is not configured, its default value is jar, which means that Maven will make the project a jar package.

The important part of this configuration is modules. The submodules included in the example are app-util, app-dao, app-service, app-war.

When Maven builds the app-parent, it organizes a build order based on the interdependencies of the submodules, and then builds them one by one.

1.3.4 Advantages

Projects built with maven have two characteristics:

  • Dependency management:

  • To make it easily understand, this feature means that disparate projects are automatically linked directly through the pom.xml configuration file, without manually managing and maintaining dependencies between these projects (including jars). This is the first feature of maven. Dependency management.

  • Project automatically built:

  • Project construction is a daily work of the deployment process. Project construction means that package the code which are written by the developer (marked as war, the web project can be deployed and packaged as long as it is packaged into a war package). Of course, this process is not only a package, but also includes the removal. , compilation, testing, reporting.

  • But the actions are given to maven include packages, and maven will automatically finish it for you. Instead of doing it manually, this is the second feature of the maven project that is automatically built. And that feature can significantly improve the efficiency of the project deployment.

  • First solve the dependency problem between the three modules of ABC, then use the parent project to manage and maintain the three ABC modules (this is called aggregation), as long as they are configured in the corresponding pom.xml file, we do not need to manually maintain these relationships.

1.3.5 How to use Maven?

There are some basic and useful commands.

  • -v: Query the Maven version.

  • This command is used to check if maven is successfully installed. After the Maven installation is complete, enter mvn -v at the command line. If relevant information of maven is output, it means that the installation is successful.

  • Compile: compile .java files.

  • This command is used to compile java source files into class files.

  • Test: test project

  • This command is used to execute the test project under the directory.

  • Package: package project

  • This command is used to mark the project as a jar.

  • Clean: This command is used to delete the target folder.

  • Install: install project.

  • Put the current project in the local repository of Maven.

1.4 Conclusion

With the help of this article, you will finish your journey in Maven. The first impression of Maven maybe has been left in your mind. You will have some basic language in your repository. So try and use Maven in your workplace and daily studying projects!

1.5 Bibliography

Images from

https://pt.slideshare.net/tibor17/maven-and-modularity-basics

http://maven.apache.org/

http://jwebsocket.org/documentation/installation-guide/build-jwebsocket-apache-maven

http://www.programgo.com/article/97292470493/

References from

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

https://www.tutorialspoint.com/maven/

https://codesjava.com/maven-pom-xml-file

A propos de SUPINFO | Contacts & adresses | Enseigner à SUPINFO | Presse | Conditions d'utilisation & Copyright | Respect de la vie privée | Investir
Logo de la société Cisco, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société IBM, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Sun-Oracle, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Apple, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Sybase, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Novell, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Intel, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Accenture, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société SAP, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Prometric, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Toeic, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo du IT Academy Program par Microsoft, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management

SUPINFO International University
Ecole d'Informatique - IT School
École Supérieure d'Informatique de Paris, leader en France
La Grande Ecole de l'informatique, du numérique et du management
Fondée en 1965, reconnue par l'État. Titre Bac+5 certifié au niveau I.
SUPINFO International University is globally operated by EDUCINVEST Belgium - Avenue Louise, 534 - 1050 Brussels