Maven and Maven
Maven has never been used before. Recently, when studying Curator, it imports other people's projects, but there is no corresponding package. Maven should be used to solve the dependency. As a result, there were still many pitfalls in the middle, although they were finally solved. Despite the corresponding installation tutorials on the Internet, many of them are vague and ambiguous. Finally, I decided to organize them myself.
1. Download Maven and configure related environment variables
As follows:
Http://maven.apache.org/download.cgi #
Decompress the package and set environment variables. Set MAVEN_HOME and PATH. Take my local settings as an example.
MAVEN_HOME: E: apache-maven-3.3.9
PATH: Add % MAVEN_HOME % \ bin after the PATH.
Run mvn-v in the DOS window to check whether output exists. The normal output is as follows:
NOTE: If no output is available, you may need to restart your computer to make the environment variable take effect.
2. Set the configuration file settings. xml of Maven.
The file is in the conf directory.
There are two changes:
1. default file storage path of Maven
<!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> -->
The default file storage path for Maven is $ {user. home}/. m2/repository. $ {user. home} indicates the home Directory of the current user.
Here, I changed it to the E: \ Maven directory on the local machine.
<!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> --> <localRepository>E:\Maven</localRepository>
2. Modify the image source of Maven
We recommend that you use an Open Source image source from China.
Modify mirrors as follows:
<mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | --> <mirror> <id>nexus-osc</id> <mirrorOf>*</mirrorOf> <name>Nexus osc</name> <url>http://maven.oschina.net/content/groups/public/</url> </mirror> </mirrors>
For other settings, refer to "use the open source Chinese Maven library help"
Http://maven.oschina.net/help.html
It contains ready-made settings. xml. You only need to modify the default file storage path of Maven.
3. Install the Eclipse Maven plug-in
Two installation methods are widely used on the Internet: Online installation and offline installation.
Offline installation can refer to: http://blog.csdn.net/guanning0109/article/details/26069277
Eclipse-maven3-plugin.7z for: http://download.csdn.net/detail/bluerebel/7407455
My first choice is to install it offline. Unfortunately, after you restart Eclipse, the Maven plug-in does not appear in "Preferences.
Finally, I was helpless. I used online installation to find that online installation is quite simple and there are no shortcomings mentioned in the above blog.
Install Maven plug-in online
Click Install New Software under Help. Enter the address "release.
For details, see http://jingyan.baidu.com/article/e6c8503c1d04d3e54f1a1807.html.
One step is missing in the above reference document, that is, after you restart Eclipse, you need to set the Maven plug-in to associate with the previously downloaded Maven software. Set in Preferences in Window.
After the above installation, the Eclipse Maven plug-in has been installed ~
In this way, Maven dependencies can be solved online.
Summary:
Looking back, the whole process is quite simple, mainly in two places:
I. At the beginning, I used the official default image source. I downloaded only one junit for a long time and repeatedly executed "Update Dependencies ", the following error is reported:
Solution: Modify the image source of Maven.
Practice has proved that the download is smooth after the Maven image source is changed.
2. Maven may have been downloaded but cannot be downloaded, or a directory has been created before. At this time, an error will still be reported when you refresh the pom. xml file, as shown below:
Although the download is smooth, several packages still cannot be downloaded.
Solution: Delete the corresponding directory and click pom. xm again.