Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Sample Analysis of installation configuration and New Project in Maven Environment

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the installation and configuration of the Maven environment and the example analysis of the new project, which is very detailed and has a certain reference value. Interested friends must read it!

What is 1 Maven?

Apache Maven is used as a software project management and understanding tool. Based on the concept of the Project object Model (POM), it can manage the construction, reporting, and documentation of a project from the core information of the project.

Maven is a project management and understanding tool. Maven provides developers with a complete build lifecycle framework. It takes little time for the development team to use the basic framework for automating the build project, because Maven uses a standard directory structure and a default build lifecycle.

In scenarios where there are multiple development teams, Maven can establish a standard way of working in a very short period of time. Because most projects are simple and reusable, Maven simplifies developers' work in creating reports, checking, building, and testing automated configurations.

Maven provides developers with a way to manage the following processes:

Project build (Builds)

Document (Documentation)

Report (Reporting)

Project dependency (Dependencies)

Software configuration Management (SCMs)

Publish (Releases)

Distribution (Distribution)

Mailing list (mailing list)

In general, Maven simplifies and unifies the project build process. It seamlessly handles project compilation, distribution, documentation, teamwork, and other tasks, increases the reusability of task processing, and handles most build-related tasks.

Maven uses the default project structure when the project is created, and the developer only needs to place the file accordingly without any configuration in the pom.xml file.

The following is the file structure generated by maven for the project you created.

2. Set up the environment 2.1 install JDK

Maven is a java-based project management tool, so you first need to check to see if maven has JDK installed before installing maven.

In a windows environment:

From the command line, run java-version. If you output the following result, it means that jdk has been installed.

Otherwise, you need to download JDK and install it.

2.2 download and install maven

Download address:

Http://maven.apache.org/download.html

Extract the downloaded files to the directory you want to install. For example:

D:\ apache-maven-3.5.0-bin

2.3 configure environment variables

Configure the MAVEN_HOME environment variable with the value of the directory you just extracted:

D:\ apache-maven-3.5.0-bin\ apache-maven-3.5.0

Add an item to the path variable:

% MAVEN_HOME%\ bin

2.4 verify that maven is installed

Enter a command on the command line

Mvn-version

If the following results appear, the installation and configuration is successful.

After you have done the above, you can use maven.

Configuration of 2.5 maven's local warehouse

There are three types of maven repositories:

Local warehouse (local)

Central warehouse (central)

Remote warehouse (remote)

The Maven local repository is a directory address on your computer, and the Maven local repository holds all your project dependencies (libraries, plug-in jar packages, etc.). When you run a Maven build, Maven automatically downloads all dependent jar packages to the local repository. This helps prevent the project's dependent references from being stored on a remote host each time the project is built.

There is a setting.xml file under the apache-maven-3.5.0\ conf path. Open the file with a localRepository tag and set its value to the path to your local warehouse.

The environment of maven has been configured above, but if you want to use it in IDE, IDE also needs to be configured. This article only describes the configuration in eclipse.

3 maven plug-in configuration in eclipse 3.1 download and install the maven plug-in

In the new version of eclipse, the maven plug-in is generally installed by default. If your IDE does not have the maven plug-in installed, you need to download the M2e plug-in from the plug-in market.

3.2 configure the environment

Under window-preference-Maven-User Settings, configure the file path of settings.xml in maven.

Under window-preference-Maven-Installations, configure the installation path for maven.

In this way, the environment for maven is set up.

Now you can use the maven plug-in to create a maven project.

4 create a maven project

Under file-new-other, select maven project.

This article only demonstrates how to create a web project, as do other types of projects, and the maven plug-in provides templates for creating various project types.

There are several concepts in the above operation:

GroupId (project organization), artifactId (project naming), version (version number), so that we can uniquely identify a project.

The specific meaning is as follows:

This generates a web project.

5 structure of the maven web project

Let's take the maven web project that the author has created before as an example to briefly explain the structure of the maven project.

(1) src/main/java: the directory where the java source files are placed

(2) src/main/resources: resource files, such as property files, etc.

(3) at the same time, the webapp directory is placed under the lib file directory (this is created by the author, mainly used to place their own imported jar package, rather than the dependency imported through maven's pom file) and web.xml.

Note: this web.xml file may not be generated by maven at the beginning, with the following error prompt:

Description Resource Path Location Type web.xml is missing and is set to true pom.xml / maven line 6 Maven Java EE Configuration Problem

But you can generate it manually, which can solve the problem that xml is not generated.

(4) src/test/java: test code storage directory

(5) the classes path under the target directory stores the compiled class files, corresponding to the test class files stored in the src/main/java,test-classes directory above.

(6) the pom.xml file under the project root directory is the most important file in the maven project.

POM, which means Project object Model (Project Object Model), is the basic unit of Maven. It is a XML file named pom.xml that always exists in the project's more directory.

POM contains project-related information and various configuration details that Maven uses to build one or more projects.

POM also includes various target operations (goal) and plug-ins. When performing a task or target operation, Maven looks for the POM in the current directory. Maven reads the POM, gets the required configuration information from it, and then performs the target operation. Some of the Maven configurations that can be explicitly listed from POM are as follows:

Project dependency (project dependencies)

Plug-in (plugins)

Target Action (goals)

Build (build profiles)

Project version (project version)

Developer (developers)

Mailing list (mailing list)

For beginners, what we are most concerned about is the project dependency. The dependency tag under the pom file defines a dependency. If we need to introduce a dependency, we can look for the jar package you are looking for in http://mvnrepository.com/, and then we can find something like this and copy the contents of the red line directly to the next level of the tag under the pom file.

In this way, the maven plug-in will download the corresponding jar package and store it in your local warehouse. If the jar package is already available in the local warehouse, then next time if you use the same jar package, you will directly drink the jar package in the local warehouse.

For the file directory structure generated by maven above, you can modify the configuration accordingly.

You can define the deployment path here. You can also remove files for directories that do not need to be deployed.

The above is all the contents of the article "sample Analysis of installation configuration and New projects in Maven Environment". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report