Maven (you must be able to understand)

Two main problems Maven solves

The first small question:

Develop two Java projects and call them A and B for the time being. Some functions in project A depend on certain classes in project B. So how to maintain this dependency?

You can type the B project into a jar package, and then import the B jar file under the Library of the A project, so that the A project can call some classes in the B project.

The second small question:

If we develop a project or make a small demo, such as using the SSM framework, then we have to find dozens of dependent jar packages used by the SSM framework and import them manually, which is super tedious. 

 

In summary, maven has two main functions

The first one to help you import the jar package you need, maven we will configure a local warehouse, you only need to import the coordinates of the jar package in pom.xml.

The second one can make the project you write into a jar package for others to use.

 

What is Maven?

 Maven is a software project management tool based on the project object model (POM project object model) , which can manage the construction, reporting and documentation of the project through a small piece of description information (configuration)

  I personally think that the core function of Maven is to reasonably describe the dependencies between projects. In layman 's terms , it is to obtain jar packages through the configuration of the pom.xml file instead of manually adding jar packages.

Maven installation , not much to say, a bunch of online.

Maven configuration

Configure the environment variables, change the warehouse address under the settings file, and fix the local warehouse.

Then when creating a maven project, configure the maven installation address, settings address, and local warehouse address , and it can be used.

 

 

Warehouse types include: local warehouse, central warehouse, remote warehouse (private service)

  • 1 ) Local warehouse: Open the settings.xml in the Maven-conf directory, you can see the comment of localRepository: Default: ${user.home}/.m2/repository, that is, the default location of the Maven local warehouse is the path under the system disk ; Generally we will use override to rewrite in the project.
  • 2 ) Central warehouse: When starting the Maven project, first look for the jar package in the local warehouse through the jar package coordinates. If it is not locally, it will go to the central warehouse to download if it is connected to the Internet. If it is not connected to the Internet, it will report an error because the jar package cannot be found. . Almost all open source jar packages are placed in the central warehouse;
  • 3 ) Remote warehouse: In the actual enterprise project development, in order to facilitate management and develop normally even if it is not connected to the Internet, a remote warehouse will be created with an alias of private server. The company can obtain the jar package from the remote warehouse through the LAN. The jar package of the remote warehouse can be uploaded locally or downloaded from the central warehouse.

Maven instructions

Cleanup: mvn clean - delete the target directory, that is, delete class files, etc.

Compile: mvn compile --src/main/java directory java source code compile to generate class (under target directory)

Test: mvn test --src/test/java directory compilation

Packaging: mvn package ---generate compressed files: java project #jar包; web project #war package, also placed in the target directory

Installation: mvn install-upload the compressed file (jar or war) to the local warehouse

Deployment|Release: mvn deploy - upload compressed files to private server

The above instructions are the life cycle of maven, compile, test, package, install, and release. It integrates directly for you, and it's done with a single click.

 

Guess you like

Origin blog.csdn.net/weixin_44126152/article/details/108316145