Recent automated tests, which involve Maven in the framework, have made a simple understanding of the deployment and integration of MAVEN in its own learning process.
----Basic environmental Information----
Personal pc:win8.1 64-bit
Java environment: JDK1.8 (configured)
Eclipse:luna Service Release (4.4.1)
maven:3.2.5 Http://apache.dataguru.cn/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.zip
I. Configuring the MAVEN environment variables
Maven downloads and extracts to the specified path
Configuring the MAVEN environment variable is similar to configuring a JDK
Take win8.1 as an example:
Traditional desktop--win+x Key--Press Y to open "system"--Advanced system settings--environment variables--New in system variables
Variable name:m3_home
Variable values: Maven root directory, such as my maven decompression at D:\Program files\maven\, the Maven root directory is D:\Program files\maven\apache-maven-3.2.5
The PATH environment variable is then appended with the Maven bin path ;%m3_home%\bin(semicolon do not repeat)
Restart your computer for the modified environment variable to take effect
-------------------------------------------
Another way to configure an environment variable that is immediately effective :
Go to command line: Win+r Open run, cmd enter
Configuration m3_home:set m3_home=Yourmavenpath
Check Result: Echo%m3_home
Path Append manven\bin:set Path=%path%;%m3_home%\bin
Check Result: Echo%path%
--------------------------------------------
Check that the environment configuration is completed correctly: In the cmd window, enter: MVN-V view version information
Second, custom warehouse location
In the settings.xml file under Maven root \conf, you can customize the warehouse location to hold all the jar packages that the project relies on (see the format and description already given in the original file):
After Setup is complete, you can run MVN help:system to view all current system information, and the first run of this command will automatically download the default pom files and jars, Mvn-help-plugin and JUnit, to the local repository, and you can view the new files in the configured local warehouse path
Third, the first project
Here's how to create our first MAVEN project from a command line:
First CD to the directory where the project is to be stored, and then run the command: MVN archetype:generate-dgroupid=yourgroupid-dartifactid=yourartifactid-dpackagename= Yourpackagename
Which Groupid,artifactid,packagename and so on will be reflected in the project's Pom.xml file
Cases:
The initial build will automatically download the required dependencies from the MAVEN central repository over the network, so depending on the network situation may take several minutes.
In the middle there will be a few need to confirm the place (callout), you can directly enter the confirmation,
When you are finished, you will print out the project information:
Where version is not specified in the command that created the project, so it remains the default, and you can specify the version number by-dversion=youversion when you create the project
At this point, we can see the project folder named Artifactid under the specified Basedir directory, for example:
Next, build the project into a format that you can import into eclipse:
Clean prior to the build cleanup (it is recommended to build a habit of pre-builds to avoid problems when the project is built, primarily for projects that have been compiled): Go to the project root directory, run mvn clean compile, and, similarly, first run to download the dependency package over the network.
Then execute the command eclipse:eclipse build the project into a structure suitable for pouring into eclipse.
After the build is completed, the compiled file storage path will be printed, and our first MAVEN project can be built to see the projects presented in the MAVEN infrastructure framework in the project directory, and the next development buddy Eclipse is coming soon.
Iv. Maven Project import Eclipse and configuration updates
The recent version of Eclipse used here, the Maven plugin that has been integrated, needs to be installed on its own if it is not integrated with MAVEN by default.
file--import--maven-existing maven Projects--next
Select the project root to import, click Finish to complete the import:
You can see that the import was successful and that a classic Hello world! has been preset in the project for testing:
We found that the MAVEN project we just built was not based on my local jdk1.8, but rather the default of 1.5, to let us create a MAVEN project based on a specific version of the JDK, there are two ways :
Mode 1:
Configured in Settings.xml under MAVEN installation directory Conf, which will take effect for all MAVEN projects that are built later
Configuration format is already commented in the Settings.xml file <profiles> section
Cases:
< Profile> <ID>jdk-1.8</ID> <activation> <Activebydefault>True</Activebydefault> <JDK>1.8</JDK> </activation> <Properties> <Maven.compiler.source>1.8</Maven.compiler.source> <Maven.compiler.target>1.8</Maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </Properties> </ Profile>
Mode 2:
Configured in the Pom.xml file in the root directory of this project, this will only take effect after the project is built.
Example: Insert the following configuration in Pom.xml
<Build> <Plugins> <plugin> <groupId>Org.apache.maven.plugins</groupId> <Artifactid>Maven-compiler-plugin</Artifactid> <Configuration> <Source>1.8</Source> <Target>1.8</Target> </Configuration> </plugin> </Plugins> </Build>
This is the latter way , which facilitates special customization for different projects.
After configuration modification, go to the project root at the command line and re-execute:
MVN Clean Compile
MVN Eclipse:eclipse
After re-importing to eclipse, check that the dependent JDK version has been updated
V. Eclipse associated Local MAVEN environment
Since the new version of Eclipse has integrated maven, we want to talk about the Maven plugin configuration for Eclipse in the local MAVEN environment in just a few simple steps:
1. Configure the installation path:
Window--preferences--maven--installations--add Select the installation path for the local Maven--finish
Because it is already configured, it will be prompted to be aleady in use
2. Configure basic settings and dependency packages:
Window--preferences--maven--usersettings, when the settings.xml path is selected, the local warehouse path is automatically adapted
Once the configuration is complete, you can create a MAVEN project based on the local MAVEN environment directly above eclipse:
File--new--other or Direct CTRL + N, select Maven project to create
You can see that the default path is already local MAVEN environment
A wide selection of templates, such as the WebApp project
Fill in the appropriate information, click Finish, and wait a moment to see the new Web project
OK, the main content of this article to the end, the text does not have a detailed explanation of the configuration and commands, the details about MAVEN can be obtained by themselves, here are listed:
1.Maven official website http://maven.apache.org/
The 2.oracle Java Community's Chinese "Apache Maven primer (Top and bottom)"
Http://www.oracle.com/technetwork/cn/community/java/apache-maven-getting-started-1-406235-zhs.html
Http://www.oracle.com/technetwork/cn/community/java/apache-maven-getting-started-2-405568-zhs.html
3.Maven Chinese Course http://www.yiibai.com/maven/
MAVEN3 Environment Building +eclipse Association (win8.1+jdk1.8)