preface
In the development, we will deal with various JAR packages from the very beginning. At the beginning of learning JAVA, we first downloaded several needed JAR packages, and then manually added them to the lib and imported them. Later, when we came to MAVEN, we learned to search the coordinates of the required JAR packages, copy and paste them, and import them automatically, all at once. Gradually, we got used to this way to introduce dependency, which was really convenient in daily development. With the development of technology, we began to contact with micro-services, and encountered jar package conflicts many times in learning. We learned that MAVEN is not only used to download a JAR package, but also provides project management and version control functions. I have also learned a lot in bits and pieces, but I have not systematically sorted out these knowledge. Here I sort them out for future reference.
What is MAVEN?
Is a tool for managing projects
By abstracting each project into a project Object model (POM) and uploading it to the central warehouse, we can introduce the required resources through coordinates for our own projects, and our projects can also be used as resources for other projects.
What does it do?
- Project build: Various plug-ins are provided to complete the project build
- Dependency management: it is convenient to manage JAR packages and avoid version conflicts between resources
- Unified development structure: Provide a standard, unified project structure
Download and install
MAVEN is an open source project management tool. We can download it directly from the official website and unzip it to use. Maven download site
Note: MAVEN is developed in JAVA and depends on the JAVA environment. You need to configure the JAVA_HOME and MAVEN_HOME environment variables, which will not be expanded here.
Configure the command line window input
mvn -v
Copy the code
If the preceding information is displayed, the installation and configuration are successful.
Some basic concepts in MAVEN
warehouse
Used to store JAR resources
- Local repository
- Remote warehouse
- Private server (solve the problem of slow access speed, private resource release)
- The central warehouse
coordinates
Locate the resource in the warehouse (GAV)
<groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> < version > 2.2.6. RELEASE < / version >Copy the code
- G: groupId Indicates the name of the organization
- A: artifactId Indicates the name of the project
- V: version Version number
- Package Ageing
Local repository configuration
Create an empty folder (resporty) in the desired location and use it as the local repository jar
Open the decompressed Maven folder Find the configuration filesetting.xml
It is recommended to make a copy and put it in our local repository directory, but you can also modify setting.xml directly
Change the address to point to the resporty folder we created
The jar packages downloaded from the central repository will be stored in the resporty folder
Because the central warehouse is on a foreign server, and the download speed is very slow, we can choose to change it into the domestic image, and the Ali image to change the image to the Ali image address
<mirror> <! -- <id> aliMaven </id> <! -- name --> <name>aliyun </name> <! Address - image - > < url > http://maven.aliyun.com/nexus/content/groups/public/ < / url > <! --> <mirrorOf>central</mirrorOf> </mirror>Copy the code
conclusion
At this point, I have a basic understanding of MAVEN, and configured the local warehouse address, switched to the domestic image, and improved the download efficiency.