Create Maven Web projects from scratch with eclipse

Source: Internet
Author: User

In this blog post, I'll start from scratch to teach you how to create a MAVEN Web project under window.

First, see if you have installed MVN
1. Press Win+r on the keyboard and enter CMD as shown:

2. Click OK, the DOS interface appears, and enter the command: Mvn-v to see if MVN has been configured in the system environment variable.

3. If MAVEN is installed, the corresponding version number and Java version number of Maven will appear.

Second, install Maven
If Maven has not been installed on your computer, you need to do this step by mistake.
1, Baidu search "maven download", or go directly to Apache Maven Project's official website: https://maven.apache.org/download.cgi#, like the following four optional download package:

Among them, 1 is the Linux under the compiled installation package, 2 is the window under the compiled installation package, 3 is Linux under the source installation package, 4 is the window under the source installation package. Here, we choose the 2nd download.
2. The directory of Maven after download is as follows:

I placed the file location under the D drive under the Maven directory (D:/maven), you can see that there are four folders, this directory structure and other Java-related programs similar, where the bin folder is placed in the executable (this we will be configured under the environment variables of the system), The boot folder is equipped with the configuration boot file, and the relevant configuration file (including the location of the MAVEN repository) is placed in the Conf, and Lib is the relevant jar package needed to execute the program.
3. Set the environment variables of the system to support the direct input of the MAVEN command:
3.1 Configuring variable types and variable values:

3.2 Configure the above variables under path:

At this point, the first step, you can see the input maven-v can see the corresponding version number.
4. Configure the location of the MAVEN local repository

Modify, Setting.xml the file as follows:

Third, install MAVEN plugin and configure in Eclispse
1. Installing the MAVEN plugin in Eclispe
1.1. Open Eclispe Marketplace, enter Maven to search, and select: Maven integeration for Eclipse (Luna) 1.5.0, such as:

1.2, click, install (Note: I have installed the plugin so display installed).
2. In eclipse, click Installations under Maven in Windows->preferences, click Add to add the location of the MAVEN that we previously configured, such as:

Set the MAVEN configuration in usersetting for our previously configured maven Setting.xml files:

Iv. Creating a maven project
Create a MAVEN project,

The following pop-up box appears, directly select Next,

Since we are creating a Web project, the skeleton we have chosen is maven-archetype-webapp to Chuanjiang the project:

Fill in the group ID and artifact ID, click Finish

At this point, the project catalog for the created projects is as follows:

Where the project's directory structure does not conform to MAVEN's directory structure:
Src/main/java
Src/main/resources
Src/test/java
Src/test/resources
View the source in the Java Build path in the properties of the project, and you can see/src/main/java and/src/test/java/missing.

So we click the Remove these two missing source files.

Manually created, non-existent three source folders:

Change the location of the output folder for the source file created above:

To change the version of the JDK:

Configure the Web Deployment Assembly, leaving only the deployment required, so/src/test/java and/src/test/resources are removed, and the deleted packages are:

When we used eclipse to create a MAVEN-structured Web project, we chose Artifact ID Maven-artchetype-webapp, because this catalog is older, The servlet is still 2.3, and it's usually at least 2.5, and when you modify the Dynamic Web module to 2.5 in project facets, it will appear cannot change version of project facet Dynamic Web module to 2.5,

In fact, on the right you can see changes to 2.5 required conditions and conflicting facets, the steps to solve this problem are as follows:

1. Change the servlet to 2.5 to open the project's Web. XML, before changing

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app>  <display-name>Archetype Created Web Application</display-name></web-app>

Switch

<?xml version= "1.0" encoding= "UTF-8"?  <web-app  version  =" 2.5 " xmlns  =" HTTP +/ Java.sun.com/xml/ns/javaee " xmlns:xsi  =" http ://www.w3.org/2001/XMLSchema-instance " xsi:schemalocation  = "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  >< /span> <display-name ;  archetype Created Web Application</display-name ;  </web-app ;  

2. Modify the project settings and open the project under Navigator. Org.eclipse.jdt.core.prefs under the Settings directory

Eclipse. Preferences. Version=1Org. Eclipse. JDT. Core. Compiler. CodeGen. Inlinejsrbytecode=enabledorg. Eclipse. JDT. Core. Compiler. CodeGen. TargetPlatform=1.5Org. Eclipse. JDT. Core. Compiler. Compliance=1.5Org. Eclipse. JDT. Core. Compiler. Problem. Assertidentifier=errororg. Eclipse. JDT. Core. Compiler. Problem. Enumidentifier=errororg. Eclipse. JDT. Core. Compiler. Problem. Forbiddenreference=warningorg. Eclipse. JDT. Core. Compiler. SOURCE=1.5

Change 1.5 to 1.6

Eclipse. Preferences. Version=1Org. Eclipse. JDT. Core. Compiler. CodeGen. Inlinejsrbytecode=enabledorg. Eclipse. JDT. Core. Compiler. CodeGen. TargetPlatform=1.6Org. Eclipse. JDT. Core. Compiler. Compliance=1.6Org. Eclipse. JDT. Core. Compiler. Problem. Assertidentifier=errororg. Eclipse. JDT. Core. Compiler. Problem. Enumidentifier=errororg. Eclipse. JDT. Core. Compiler. Problem. Forbiddenreference=warningorg. Eclipse. JDT. Core. Compiler. SOURCE=1.6

Open Org.eclipse.wst.common.component

<?xml version= "1.0" encoding= "UTF-8"?><project-modules id="Modulecoreid" project-version="1.5.0" >    <wb-module deploy-name="Maven-project">        <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="Defaultrootsource"/>        <wb-resource deploy-path= "/web-inf/classes" source-path="/ Src/main/java "/>        <wb-resource deploy-path="/web-inf/classes" source-path= "/src/main/resources"/>        <wb-resource deploy-path= "/web-inf/classes" source-path="/src/ Test/java "/>        <wb-resource deploy-path= "/web-inf/classes" source-path="/src/ Test/resources "/>        < property name="Context-root" value="Maven-project" />        < property name="Java-output-path" value="/maven-project/target/ Classes "/>    </wb-module></project-modules>

Change project-version= "1.5.0" to project-version= "1.6.0"

<?xml version= "1.0" encoding= "UTF-8"?><project-modules id= "modulecoreid" project-version=" 1.6.0 ">    <wb-module deploy-name="Maven-project">        <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="Defaultrootsource"/>        <wb-resource deploy-path="/web-inf/classes" source-path= "/src/main/java"/>        <wb-resource deploy-path= "/web-inf/classes" source-path="/src/ Main/resources "/>        <wb-resource deploy-path= "/web-inf/classes" source-path="/src/ Test/java "/>        <wb-resource deploy-path="/web-inf/classes" source-path= "/src/test/resources"/>        < property name="Context-root" value="Maven-project"/>         < property name="Java-output-path" value="/maven-project/target /classes "/>    </wb-module></project-modules>

Open Org.eclipse.wst.common.project.facet.core.xml

<?xml version= "1.0" encoding= "UTF-8"?><faceted-project>  <fixed facet="Wst.jsdt.web"/>  <installed facet="java" version="1.5"/>  <installed facet="Jst.web" version="2.3"/>   <installed facet= "wst.jsdt.web" version="1.0"/ ></faceted-projec 

Change it into a

<?xml version= "1.0" encoding= "UTF-8"?><faceted-project>  <fixed facet="Wst.jsdt.web"/>  <installed facet="java" version="1.6"/>  <installed facet="Jst.web" version="2.5"/>   <installed facet="Wst.jsdt.web" version="1.0"/></faceted-project>

After you've changed it, you've changed the Dynamic Web module to 2.5 when you open it.

Create a workable eclipse of the Web project structure as shown in:

Create Maven Web projects from scratch with eclipse

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.