What is maven?
MAVEN is a tool for building projects that easily manage the life cycle of your project. That is, the project's jar package relies on, develops, tests, releases packaging.
Let me summarize some of its features below, and look at these features, perhaps more about Maven.
1 Jar Package Dependency
This might be the most prominent feature of Maven. Using MAVEN does not require the Internet to download the jar package separately, only to configure the jar package dependencies in the configuration file Pom.xml, you can automatically download the jar package to our project. This way, when others develop or use this project, they do not need to copy the jar package back and forth, just copy the pom.xml to automatically download the jar packages.
Moreover, we download the jar package ourselves, and it is possible to create inconsistencies in the version so that it is possible that the code will run inconsistently during the collaborative development process. This problem does not occur by using Maven's exact matching jar package.
2 Project coordinates
MAVEN defines the project name with a specific identity, so that it can uniquely match other jar packages or be published so that others can use their own publishing products. This logo is called the coordinates, the long is actually very common, is simple XML only:
1 <groupid>com.test</groupid>2 <artifactid>maventest</artifactid>3 < Version>0.0.1-snapshot</version>4 <packaging>jar</packaging>5 6 <name> Maventest</name>7 <url>http://maven.apache.org</url>
groupId: The project name, since some items are not made of a jar package, but consist of a lot of jar packages. So this groupid is the name of the whole project.
Artifactid: The name of the package.
Version: revision number.
Packaging: The type of package, usually a jar, or a war. If not, the default is the jar.
name and the URL, one is the names and one is the address of Maven. The main is the above several parameters.
When you want to rely on what jar, you can rely on the following way:
1 <dependencies>2 <dependency>3 <groupid>junit</groupid>4 <artifactId >junit</artifactid>5 <version>3.8.1</version>6 <scope>test</scope>7 </dependency>8 </dependencies>
The contents of each attribute are basically the same.
Note here that the naming rules for jar packages are:
Artifactid-version[-classifier].packaging
For example, the pom.xml generated jar package name above is: Maventest-0.0.1-snapshot.jar.
The classifier here is optional, but some projects may also need to export some attached files, such as Javadoc,source and so on, then this place will need to configure a string. It's usually jdkxxx or something like that.
3 Test Drive
MAVEN is a test-driven development idea, so the project was initially created with two folders, main and test. A Java file for placing the development, one for writing test unit tests. This allows you to design unit tests in advance of each development to help reduce bugs.
Back to top how to use Maven in eclipse
The eclipse I'm using has its own Maven plugin, so it can be created directly. This does not show you how to install MAVEN. Here's how MAVEN projects are created:
1 How to create a MAVEN project:
Click New directly, you can find the Maven tab, click Maven Project to create MAVEN project
2 Select the default project location
3 Create the project, red is the creation of the ordinary Maven project. Pink is the creation of Web engineering.
6 fill in the relevant GroupID Artifactid version and other information
Click Finish to create a simple MAVEN project.
Back to the top what does maven project look like?
The MAVEN project is generally structured as follows:
First_maven |--pom.xml '--src |--main | | --java | | '--com | | '--Test | | '--App.java | '--Resources | '--Meta-inf | '--application.properties '--Test '--Java '--com '--Test '--Apptest.java
pom.xml: A dependency used to define or add a jar package
Src-main: For storing Java source files
src-test: Used to store test cases.
The target folder may also appear under the project, which is used to generate the corresponding class file or the released Jar package.
Go back to the top of the eclipse in the MAVEN common commands
Click Run as to find a few MAVEN commands:
Maven Build:
This command is used to compile the MAVEN project, and the corresponding class file is generated in the classes in the target folder after executing the command.
Maven Clean:
Delete the target folder, which deletes the generated package packages and files such as class.
Maven Test:
Compile automatically before running all of the test cases.
Maven Install:
Publish builds the corresponding package packages.
Attention:
Note that the command above, build and test will generate the corresponding class file. That is, when you create a new MAVEN project, or clean a maven project, if you do not use these two commands, directly test against the class, will run out of Java.class.notfound error. Because the class file is not compiled at this time.
Unit tests can be performed on a class only after using the two commands above.
Turn from Maven (Eclipse edition)
Go Maven Stuff (Eclipse edition)