Maven-maven installation and configuration in Eclipse

1. Install and configure Maven environment variables

1. Enter in the cmd console: echo %JAVA_HOME% to see if the path information of the java home can be displayed;

2. echo %JAVA_HOME% to see if the path information of java home can be displayed;

3. Enter: java -version in the control bar to see if the version information of java is displayed;

4. Download the official website: http://maven.apache.org/download.cgi;

5. Download the compiled version apache-maven-3.3.9-bin.zip and extract it to C:\Park_Software\apache-maven-3.3.9;

6. Configure environment variables:

(1) Create a new environment variable: M2_HOME = C:\Park_Software\apache-maven-3.3.9 Note that a semicolon cannot be added after the HOME variable;

(2) Add Path variable: ;%M2_HOME%\bin;

7. Check whether the configuration is successful in the console:

(1) cmd input: echo %M2_HOME%

(2) cmd input: mvn -v

(3) If it is displayed normally, the configuration is successful.

8. Modify the Maven repository path location:

(1) For example, if I want the warehouse location to be located on the D drive, create a new folder on the D drive: D:\m2\repository

(2) Configure the setting.xml configuration file in the C:\Park_Software\apache-maven-3.3.9\conf folder: find the localRepository tag and modify it to: <localRepository>D:/m2/repository</localRepository> ;

(3) Copy the setting.xml file to the D:\m2 folder.

Second, Maven installation directory analysis

1.bin directory

This directory contains scripts run by mvn to configure Java commands;

2.boot directory

Contains only one file: plexus-classworlds-2.5.2.jar, is a class loader framework, equivalent to the default loader for java classes.

3.conf directory

Contains settings.xml, an important configuration file that can globally customize Maven's behavior

4.lib directory

This directory contains all the Java class libraries required by the Maven runtime.

LICENSE.txt
NOTICE.txt

Documents the third-party software included with Maven.
README.txt

3. Set up HTTP proxy

(I failed many times when installing the Maven plugin in Eclipse before, and I don't know if the HTTP proxy was not set before, so it's better to configure it)
First, enter in cmd: ping repo1.maven.org, if If you can't ping the same, you must set the proxy first. The way to set it is:
enter the directory ~/.m2/ and find the settings.xml file (if not, copy %M2_HOME%/conf/settings.xml directly to the directory), and then add the following information to the <proxies> tag:

 1 <proxies> 
 2 <proxy>
 3   <id>my-proxy</id>
 4   <active>true</active>
 5   <protocol>http</protocol>
 6   <host>114.212.80.250</host>
 7   <port>80</port>
 8 
 9 
10   <username>PARK</username>
11   <password>****</password>     
12   <nonProxyHosts>www.park.com|*.host.com</nonProxyHosts>
13 </proxy>

Among them, the <host>, <username>, <password> tags can be changed to their own IP address, host name and password.

 

Fourth, configure Maven in Eclipse

4.1

1. Open Eclipse, click the Help tab, click Install new software, and then select the Add option:
2. In the Name field, enter: m2e;
3. In the Location field, enter: http://download.eclipse.org/technology/m2e/ releases;
4. Select the searched Maven plugin and click next.
5. It may take a while to install the plug-in, and you need to restart Eclipse after installation.
6. Create a Maven project
in Eclipse 7. Click File -> New -> Others -> Maven Project in Eclipse to create your own Maven project.

Enter your own name in GroupId and ArtifactId, as shown in the following figure:

 

 annotation:

(1) group Id: Defines which group the project belongs to. This group is often associated with the organization or company where the project is located. For example, if Apache creates a project named myMaven, the groupId is: com.apache.myMaven;
(2) artifact Id: defines the unique ID of the current Maven project in the group. For example, the project com.apache.myMaven has the following artifactIds: myMaven-util, myMaven-domain, myMaven-web, etc.;

4.2

Eclipse automatically generates Maven projects, and the directory structure is shown in the figure:

 

 Directory Analysis:

(1) src/main/java: This directory is mainly used to store java source code;
(2) src/test/java: This directory is mainly used to store test code;
(3) Maven Dependencies: Here are mainly jar files managed by Maven;
(4) target: used to store the bytecode files compiled by Maven;
(5) pom.xml: the full name is Project Object Model, the project object model defines the basic information of the project, which is used to describe how the project is constructed and declare the project dependency etc.
(6) src: used to store other files and other resources that will be used in main and test.
(7) In App.java in the src/main/java directory, there is already a simple applet of HelloWorld.java, which can be tested and run.

 4.3

Pack

You can specify the type to be packaged in pom.xml. If not specified, the default is .jar. The
packaging process is: in the project root directory, execute the command mvn clean package, and then you can find the package just packaged in the ./target/ directory Generated jar package.


At this point, the installation of Maven has been completed, as well as how to create a new Maven project in Eclipse, and how to package the project, and then use the actual project to further understand Maven.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325139522&siteId=291194637