Many of today's GitHub projects have been built with Maven, and the very cloudy platform is also recommended for use with MAVEN, and the use of MAVEN is becoming more and more widespread, with the same ant,gradle as Maven, where I'll focus on Maven, Because he is also the most popular now.
----------------Prepare for Work-------------
JDK more than 1.5 Java development environment.
Eclipse IDE one.
Maven 3.0.3 Download Address: http://maven.apache.org/docs/3.0.3/release-notes.html
First step: Configure the MAVEN environment
Unzip the download file and set the MAVEN environment
If you've configured the JDK, it should be easy for you. As my MAVEN environment is: F:\maven\apache-maven-3.0.3
My Computer-----Properties----Advanced-----Environment Variables-----Environment Variables-----NEW
Variable name: m2_home
Variable Value: F:\maven\apache-maven-3.0.3
Find path
At the end of the value of the environment variable add:;%m2_home%\bin;---front note semicolon
Of course, you can also add directly to the path:; F:\maven\apache-maven-3.0.3\bin is just a little more elegant in the way above.
I am newly established
Open a command prompt (start---run---cmd) and check our Java environment and MAVEN environment for errors.
Step Two: Modify Warehouse location
Modify our warehouse address to store all the jar packages that our project relies on.
My warehouse path: F:\maven\repo----This path is created by myself and you can create the path in any location.
We open the Setting.xml file in the \apache-maven-3.0.3\conf\ directory and set it to the warehouse path we created.
Let's use a command to verify the following. Open a command prompt, enter: mvn help:system
This command prints out all of the Java System Properties and environment variables. This information is very helpful to our daily programming work.
If there is no error in the running process, open our warehouse (F:\maven\repo) will find some more files inside. These files are downloaded from MAVEN's central repository to the local repository.
Step three: Create a MAVEN project
Create a project of our own.
We create a project through the MAVEN command line
MVN archetype:create-dgroupid=com.chongshi.test-dartifactid=hello-dpackagename=com.chongshi.test-dversion=1.0
Because it was the first time the project was built, all the dependent jar packages were downloaded from Maven's central repository, so it took time to wait. After we have accumulated our common jar packages in our local warehouse, our development will become very normative and convenient. ^_^!!
With the time to download the jar package, let's take a look at the Pom.xml file.
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
< modelversion>4.0.0</modelversion>
<groupId>com.chongshi.test</groupId>
< artifactid>hello</artifactid>
<version>1.0</version>
<packaging>jar</ packaging>
<name>hello</name>
<url>http://maven.apache.org</url>
< properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</ properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope> test</scope>
</dependency>
</dependencies>
</project>
The top-level element in the Øproject:pom.xml file;
Ømodelversion: Indicates the version of the object model used by POM. This value is rarely changed.
Øgroupid: Indicates the unique identification of the organization or team that created the project. GroupID is a key identification of the project, typically defined with the fully qualified name of the organization. For example, Org.apache.maven.plugins is the GroupID specified by all MAVEN plug-in projects.
Øartifactid: Indicates the base name of the primary product produced by this project. The main product of a project is usually a jar file. Second, like a source code package, Artifactid is usually used as part of the final name. The typical product name uses this format: <artifactid>-<version> <extension> (for example: Myapp-1.0.jar).
Øversion: The version number of the project product. MAVEN helps you manage your version, and you can often see this version of snapshot, indicating that the project is in the development phase.
Øname: The display name of the project, which is typically used in a document produced by Maven.
Øurl: Specifies the project site, which is typically used in a document generated by MAVEN.
Ødescription: Describes this project, which is typically used in documents generated by MAVEN.
Only the following part of a project is what we need to focus on:
<groupId>com.chongshi.test</groupId>
<artifactId>hello</artifactId>
<version>1.0</version>
Fourth Step: Compiling project code
Our project has been created and completed. But we opened the catalog and found that it wasn't the project directory format we needed for Eclipse. We need to build it into a project that our eclipse can import.
At the command prompt, go to our created project directory (F:\maven\hello) and execute: mvn cleancompile
Clean tells Maven to clear the input out directory target/,compile tell Maven to compile the project main code.
Don't worry, we need some time to download the related jar package. ^_^! Use Maven for the first time to learn to be calm.
The project is compiled, but the directory structure of the project is not the project structure of the eclipse we want to import into eclipse. So, you also need to execute a command:mvn eclipse:eclipse
After the command has been completed, we need the project directory.
Fifth step: Import Eclipse Tools
Open our Eclipse tool.
Configure the Maven warehouse path First
Window----perferences-----java-----Build Path-----Classpath Variables
New class path for a variable.
Name:m2_repo Note that the name must be capitalized.
Path:f:/maven/repo Click "Folder ..." to find a location with local warehouses.
Next, you can import my Hello project. How Eclipse imports the project, I'm not going to say it here, if you're a Java developer.
Sixth step: Package Update and download
Open Project found that our junit is 3.8.1, a little old. I'd like to change it to 4.7, and how to change it through MAVEN. In fact, it's very simple to open the Pom.xml file under our project.
..... <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId> junit</artifactid>
<version>4.8.1</version>
<scope>test</scope>
< /dependency>
</dependencies>
...
Change the version number of the JUnit, and then perform again: MVN eclipse:eclipse
Maven Central Warehouse Address: http://search.maven.org
If we want to download a struts jar package. Search for strruts in the search box to list all the struts versions in the Central warehouse.
The format of the list corresponds to the format of our pom.xml configuration file.
We add in the Pom.xml:
<groupId>stuts</groupId>
<artifactId>struts-scripting</artifactId>
<version>1.0.1</version>
Then update the project to download any jar packages we want from the Central warehouse (must be open source packages)