Build a Web project using Eclipse + Maven

Source: Internet
Author: User
Environment preparation: JDK: 1.6 Eclipse: Indigo3.7.2-http://www.eclipse.org/downloads/packages/release/indigo/sr2Maven:apache-maven-3.1.0-http://maven.apache.org/download.cgi1.Maven

Environment preparation:
JDK: 1.6
Eclipse: Indigo 3.7.2-http://www.eclipse.org/downloads/packages/release/indigo/sr2
Maven: apache-maven-3.1.0-http://maven.apache.org/download.cgi


1. Maven
1.1 install Maven
Decompress the downloaded Maven zip package and place it in F: \ Tool \ apache-maven-3.1.0
Set environment variable MAVEN_HOME = F: \ Tool \ apache-maven-3.1.0
Append user variable: append % MAVEN_HOME % \ bin to path
Open cmd and run mvn-version to check whether maven is correctly installed.


1.2 Maven Configuration:
Modify maven repository location: F: \ Tool \ apache-maven-3.1.0 \ conf. settings. xml
F:/Tool/apache-maven-3.1.0/repo


1.3 run Maven
Open cmd and run mvn help: system
Maven downloads a lot of things from the remote repository.


2. Install the Maven Eclipse plug-in
2.1 plug-in Installation
Eclipse3.7 and later versions can be installed through Eclipse Marketplace.
Open Marketplace, search for Maven, and find Maven Integration for Eclipse for installation.
2.2 configure Maven in Eclipse
Window --> Preferences --> Maven
2.2.1 click Installation --> click Add to Add a local MavenF: \ Tool \ apache-maven-3.1.0
2.2.2 click User Setting to ensure that the file location of Maven setting is F: \ Tool \ apache-maven-3.1.0 \ conf \ settings. xml
Note: If the configuration is not changed, use the default settings of Maven, And the Jar reference will be messy during web project creation.


3. Create a Web project using Maven
3.1 create a Maven Project
File-> New-> Other-> Maven Project
3.2 select the project path Usedefault Workspace location.
3.3 select the project type, enter the web in the search box, and select maven-archetype-webapp.
3.4 enter the Group ID, Artifact ID, and Package
The unique identifier of the Group ID project. Artifact ID is the sub-project name. The Package is a default Package.
3.5 change the project into a Dynamic Web project
Right-click the Project, select Project Facets, and click Convert to faceted from...
Select Dynamic Web Module and Java. You can also select other required components, such as Javascript.
JDK settings must be consistent with the Dynamic Web Module Version. 3.0 is Java7 and 2.5/2.3 is JDK1.6. Because the local machine is jdk1.6, You must select Dynamic Web Module Version 2.5.
After completing the preceding settings, click OK. The Properties window is closed. Right-click the project and a Deployment Assembly will appear in the list on the left.
3.6 configuration items
Make sure that the project contains three Source Folder: src/main/java, src/test/java, and src/test/resources. Note that Source Folder is not a common Folder.
3.7 change the class path
Right-click the project, and there should be four folders under Java Build Path-> Source, src/main/java, src/main/resources, src/test/java, src/test/resources.
Select Allow output folders for source folders
Double-click the Output folder of each folder to view the target path.
Src/main/java, src/main/resources, and select target/classes;
Src/test/java, src/test/resources, and select target/test-classes;
Change JDK version: Double-click JRE System Library in Libraries to confirm the JDK version you need. The local version is 1.6
3.8 set Deployment Assembly (Web Deployment Assembly)
3.8.1 Delete the WebContent and add src/main/webapp.
3.8.2 configure to publish the jar package of Maven to lib.
Add-> JavaBuild Path Entries-> Maven Dependencies-> Finish
Http://img.my.csdn.net/uploads/201211/23/1353639542_8233.png
3.8.3 release
Run As-> Maven install
Run on server

 

Related Article

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.