This article is from: http://my.oschina.net/u/1540325/blog/548530
Build a Maven project in eclipse
1
environment installation and distribution
MAVEN is a software project management tool that is based on a Project object model (POM) that can manage the construction, reporting, and documentation of a project through a short description of the information. Maven primarily serves the Java platform-based project building, dependency management, and project information management, whether it's a small open source class library project or a large enterprise application.
To put Maven in the installation process and configure Maven in Eclipse, see my blog in Open source China:
http://my.oschina.net/u/1540325/blog/493922
1.1 Building a Java project with Maven
1 "Using Maven in DOS to build Java projects look at my view of the Open source China Blog:
http://my.oschina.net/u/1540325/blog/495823
2 "Building projects with Maven under Eclipse
1) Create a simple MAVEN project
Click the Eclipse menu bar File->new->ohter->maven to get the dialog box as shown:
Select Maven Project and click Next to the next dialog box
Continue clicking next to get the following dialog box
Select Maven-archetype-quickstart, click Next to get the following:
Fill in the GroupID, artfactid,version and other information as shown, click Finish.
Simply explain the Group ID, Artifact ID, Version, and package:
Groupid:group translation into Chinese is the group, the group's consciousness, GroupId is such a group or group ID, take Apache to say good, apache everyone is not unfamiliar it,
Apache Online has a lot of projects, each project will certainly be able to find org.apache.xxxx, and Org.apache is here to say groupId
Artifactid: or Apache, Apache online has a lot of projects, and each project name is here Artifactid, in other words, Artifactid is your project name
Version: There is no good explanation for this, it's the project version.
Package: This also has nothing to say, is Groupid.artifactid, the creation of the time will automatically help you to complete, if not automatically help you fill up your own manually knocked Up
As a result, we have successfully created a simple MAVEN project with a project structure
2) Creating a MAVEN Web project
Action is similar to creating a simple Maven project, click the Eclipse menu File->new->other->maven->maven project
In the Select Maven-archetype interface, do the following:
Click Next, fill in the appropriate groupid,artifactid,version and other information, click Finish
The resulting MAVEN Web project structure is shown in
Describe the directory structure
Src/main/resources: Used to store resource files (default will help you create this resource folder)
Src/main/java: Used to store Java source files (you need to create them manually)
Src/main/test: Used to store the test code (need to create their own manually, also some people used to name: Src/test) @
Target: A place to store Maven compiled bytecode
Maven Dependencies: A maven-managed jar file in the inside
Run a MAVEN managed project,
. 3) run the MAVEN command
Right-click the project and click Run as, such as:
You can see a lot of existing MAVEN commands, click to run, and see the running information in the console
If the MAVEN command you want to run is not found here, click Maven Build to create a new command, as shown in the following:
If you fill in the Maven command, click Run
The new Maven command can be found in the following ways and run again:
It is common to run Maven install. If a Java project generates a jar package, if a Java Web project generates a war package,
Then the Java Web can be run with Tomcat.
1.2 Maven's compilation process
In fact, we generally use the MVN install command to package the project directly at a time, do not have to perform the rest of the MVN compile, MVN packages and other commands, because the implementation of the MVN install command, will be executed in these commands, now we can look at MVN What Intall has done:
Initialize initializing some environments
Process-sources processes the Project master resource file, which is typically a variable substitution of the contents of the/src/main/resources directory, and is copied into the project's main classpath directory.
Compile compile the main source of the project, is generally Src/main/java
Process-test-sources working with Project test resource files
Test-compile test code for compiling a project
The package packages the compiled code
Install installs the installation package to the MAVEN local repository for use by other local MAVEN projects
Build Maven project in Eclipse (reprint)