Maven literacy tutorial

Since the last interview came back, he found himself ignorant of maven, began fierce fill knowledge (of course, not fierce taste will slowly fill). . .

A. understand the stage

First maven clarify a few questions.

What 1.maven that?

2. Why maven?

3.maven can you do?

※ For the first question. Referral dark horse tutorial a few words:

  maven is an open source project under the apache, is a pure java development, java and only used to manage the project.

  That is a management tool maven java project.

※ Why maven?

  Traditional project a lot of jar packages taking up too much space, but directly to the maven jar package proposed, the project jar package and separated from the jar package on the local warehouse, calling for various projects.

  Incidentally, with the dark horse, then mention maven benefits :

    . A unified management of the jar package, saving space (commonly known as: dependency management)

    b a key building. (mvn tomcat: run will be able to project up and running)

    c. cross-platform

    d. for large-scale projects can improve development efficiency

※  Maven can you do?

  Compile the test (junit) Run the Package deployment

 

B. experimental stage

You can choose gearing up, and let's try to do how to use maven.

First of all, you have to configure the look maven environment variables .

  The first step you need to have jdk environment.

  1. My Computer and right click -> Properties -> Advanced System Settings -> Environment Variables bottom right corner

  2. In the System variables in this column, click New, fill in the name of the variable JAVA_HOME, variable values ​​fill C: \ Program Files \ Java \ jdk1.7.0_13 (variable values ​​in accordance with their own jdk position to fill)

  3. Locate the system variables path variables after the variable values ​​into C: \ Program Files \ Java \ jdk1.7.0_13 \ bin (variable values ​​in accordance with their own jdk position to fill)

  The second step you need to have a maven.

  1. walk's official website: http://maven.apache.org/download.cgi

  2. Download directly to extract it.

  The third step is to configure your maven global variables.

  1. My Computer and right click -> Properties -> Advanced System Settings -> Environment Variables bottom right corner

  2. In the System variables in this column, click New, variable names fill MAVEN_HOME, the value of the variable fill E: \ maven \ apache-maven-3.3.9 (variable values ​​in accordance with maven good position to fill their own decompression)

  3. Locate the system variables path variables, fill in behind the variable value E: \ maven apache maven-3.3.9-\ bin \ (variable values ​​in accordance with their own maven position to fill)

  The fourth step you have to specify what the local repository for easy storage jar your package. (Not specified, the default file on the C drive .m2 user directory folder)

  Open extract from the maven package, find conf directory, point go looking settings.xml, with notepad ++ or other similar software to open Notepad, add localRepository label in the middle of the tab settings, fill in the position you want to place a jar. Like this:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- 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\repository</localRepository>

  Specify the location of their own.

 

Next, look at the maven of common commands.

  1.mvn clean clean up your compiled file (cleared away the target file)

  2.mvn compile file compile home directory

  3.mvn test code is compiled and run test directory

  4.mvn package package

  5.mvn install publish the project to a local warehouse

  6.mvn tomcat: run a key to run the project

Which, compile test package install is a sequential.

  When you execute the test command will first execute compile command;

  When the package command execution, execution will first compile and test command;

  When the install command will first execute compile, test, and package command.

 

Finally, talk about maven three life cycle

  1.clean life cycle

     mvn clean

  2.default life cycle

     mvn compile, mvn  test , mvn  package, mvn  install ,mvn  deploy

  3.site life cycle

     mvn site (the implementation of the project will generate a complete site documentation)

  About the relationship between the life cycle and commands

    Command different life cycles can be performed simultaneously

    比如:mvn clean package

Guess you like

Origin www.cnblogs.com/sapoo/p/11074888.html