Use of the framework starts with Maven

Source: Internet
Author: User

When programmers have been downloading Java frameworks such as spring and hibernate for so long, they all download them from the official website one by one. MAVEN has never been used.

Maven makes downloading jar very convenient.

At the same time, it is also a good helper to implement all aspects of the project, such as compilation, unit testing, packaging, publishing, and so on. Following the process allows us to develop rigorous habits.

Of course, at present, I still use it to help download the jar.

 

Check Java installation

Maven is a Java tool dependent on java. Java must be installed first. It is recommended that the Java version should not be too low.

  • Check whether Java is installed on the computer.
  • Whether Java environment variables are configured (my computer> Properties> advanced> environment variables> New System variables "). For example, if my java directory is D: \ java_tools \ jdk1.6.0 _ 04, the configuration is as follows:
    • Create java_home as D: \ java_tools \ jdk1.6.0 _ 04
    • Append the bin directory under the java_home directory to the path, for example, % java_home % \ bin.

 

Download and install Maven

After confirming that Java has been installed and configured, officially start Maven Installation

  • Download Maven. Maven official website is Maven.
  • It does not need to be installed. decompress it to the directory you want to install.
  • Then configure the environment variables. For example, if my Maven directory is D: \ java_tools \ apache-maven-3.2.2, you need to set the following environment variables:
    • M2_home is D: \ java_tools \ apache-maven-3.2.2
    • M2 is % m2_home % \ bin
    • Maven_opts is-xms256m-xmx512m (this item is optional)
    • Check whether the bin directory of the Java home directory is correctly set under java_home and path (as mentioned above)

 

Test successful

After the environment variables are prepared, you can test whether the installation is successful.

  • Open the command line mode;
  • Run the Java-version command. If the Java version information is displayed, the Java installation is correct.
  • Run MVN -- version. If the maven version information, home path, and Java version information are displayed, the maven installation is successful.

 

So far, Maven has been successfully installed!

Maven is powerful. I am also a Maven learner. The following are the commands used in my work and life. Take notes and use them as a reference.

 

Create a WEB Project

Here is to create a web project, of course, you can also create a Java project and so on.

Maven has many commands. When you execute a command for the first time, Maven may need to download the corresponding file and the file on which the file depends, therefore, we need to wait for the download when executing the command for the first time. We do not need to download the command for over 2nd times.

mvn archetype:create -DgroupId=com.nicchagil.mybatis3spring3Intg -DartifactId=mybatis3spring3Intg -DarchetypeArtifactId=maven-archetype-webapp
Maven create

After creation, it is stored in the user directory by default, such as c: \ Documents ents and Settings \ nickhuang.

 

Download the jar package

The new project root directory contains the Pom. xml file.

Go to the official website of the required open-source software and copy the maven-based dependency node to the dependencies node of the newly created Project Pom. xml.

For example, the dependency of Spring framework 3.2.9

<dependency>        <groupId>org.springframework</groupId>        <artifactId>spring-context</artifactId>        <version>3.2.9.RELEASE</version>    </dependency>
Spring framework 3.2.9-dependency

 

The Pom. XML after adding the dependency of Spring framework 3.2.9 is:

<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/maven-v4_0_0.xsd">  <modelVersion>4.0.0</modelVersion>  <groupId>com.nicchagil.mybatis3spring3Intg</groupId>  <artifactId>mybatis3spring3Intg</artifactId>  <packaging>war</packaging>  <version>1.0-SNAPSHOT</version>  <name>mybatis3spring3Intg Maven Webapp</name>  <url>http://maven.apache.org</url>  <dependencies>    <dependency>      <groupId>junit</groupId>      <artifactId>junit</artifactId>      <version>3.8.1</version>      <scope>test</scope>    </dependency>        <dependency>        <groupId>org.springframework</groupId>        <artifactId>spring-context</artifactId>        <version>3.2.9.RELEASE</version>    </dependency>      </dependencies>  <build>    <finalName>mybatis3spring3Intg</finalName>  </build></project>
Pom. xml

 

Then execute any command containing the Steamed Stuffed Bun task, MAVEN will automatically download the jar package, as shown in

MVN install

If your project has been installed before, run the following clean command before installation.

MVN clean

 

Source code download

Use the following command to download the jar source code used in the project. find the corresponding category in the M2 \ repository \ directory, for example, in c: \ Documents ents and Settings \ nickhuang \. m2 \ repository \ org \ springframework \ spring-core \ 4.0.6.release

MVN dependency: Sources

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.