Maven + myeclise integration, Web project creation, and import of ready-made Web projects __web

Source: Internet
Author: User

1. Creating a WebApp project with maven ----because it is generally necessary to follow a certain directory structure when using MAVEN, although you can also use a different directory structure. However, it is not yet familiar with how to modify the Pom.xml file to achieve the goal, and modifying too many default configurations is not good for maven.

To create a method, use the command in a directory: MVN Archetype:generate-darchetypeartifactid=maven-archetype-webapp. Follow the prompts to enter the appropriate parameters, the intermediate process is as follows:

  C code    d:\study\workspace4>mvn archetype:generate -darchetypeartifactid= maven-archetype-webapp   [info] scanning for projects...   ....   [ info] generating project in interactive mode   Define value for  property  ' groupId ': : com.xjd   define value for property  ' Artifactid ': : mywebapp   define value for property  ' version ':   1.0-SNAPSHOT: :   define value for property  ' package ':   com.xjd: :   confirm properties configuration:   groupId: com.xjd    artifactid: mywebapp   version: 1.0-snapshot   package: com.xjd     Y: : Y   ....   [info] build success   [info]  -----------------------------------------   [info] total time: 1:46.199s   [info]  finished at: wed nov 09 15:02:18 cst 2011   [INFO] Final  Memory: 6M/15M    

The

Finally created a Maven WebApp project under the folder "MyWebApp" under the folder root of the project (see the procedure above), which has a structure of

  Java code    mywebapp        +---pom.xml         +---src              +--- main                      +---resources                      +---webapp                                 +---index.jsp                                +--- web-inf                                            +---web.xml                          

2. Activate the Maven plugin for configuration MyEclipse ---I'm using MyEclipse8.5, which itself comes with a plugin called maven4myeclipse, which only needs to be activated and configured.

Activation method: Window-->preference-->myeclipse-->maven4myeclipse, tick check box (Enable mave4myeclipse features).

Configuration method: Just under the node that the activation method opens, there is a MAVEN node, which expands the node, primarily configuring two nodes under it, as follows:

Installations: This node uses the built-in MAVEN by default, we need to use our installed Maven, point "add", add a maven that we externally install, note that after adding it, tick on.

User Settings: The default is the. m2/settings.xml file in the C-drive user directory, where you configure the externally installed MAVEN usage profile, as I am using the MAVEN installation directory under the conf/ Settings.xml file, select the "Update Settings" button below and don't forget to click on it.

3. Use MyEclipse to import a project created by Maven :

There are two ways to import a tutorial here:

1) use MyEclipse General engineering to import, the steps are as follows:

1> Open DOS First, run under the project Root (mywebapp): MVN eclipse: When eclipse---finishes running, you will find two more files in the project directory. Classpath and. Project, which is the project file for Eclipse, and of course MyEclipse also recognizes

2> Use the Import function in MyEclipse, select File-->import...-->existing Projects into workspace, select Project Catalog, import

3> associated maven, after the project is just a common Java project, and will not be associated with MAVEN plug-in, at this time in the project right click-->maven4myeclipse-->enable Dependency Management, so that the project is associated with the Maven plugin (the link will have an M ID on the upper left corner of the project root node).

2) Use the MAVEN project in MyEclipse to import the following steps:

1> Use the Import function in MyEclipse, choose File-->import...-->existing Maven Projects (here), select the project directory, import. ---here to import into, MyEclipse may update the index, very slow, we can cancel (in the Progress panel midpoint that big red box), then the project came in, but did not perform the operation, such as Maven Dependcy check, and so on, at this time 2nd step operation.

2> Update project configuration, right-click Project-->maven4myeclipse-->update Project Config

4. Complete the project's directory structure , the 1th step in the creation of the MAVEN project directory is not complete, such as our Java code, our test directory, etc., are manually created, and complete as follows:

  C code    mywebapp        +---pom.xml         +---src              +--- main                      +---resources                      +---java   << add                       +---webapp                                 +---index.jsp                                 +---web-inf                                            +---web.xml               +---test   << add                       +---resources    << Add                       +---java   << add          +---target   <<eclipse auto add                +---classes   <<eclipse auto add                 +---test-classes   <<eclipse auto add   

Screenshots:


5. Add MyEclipse Web Project features

So far, we've just imported a maven webapp into the MyEclipse, but in MyEclipse it's just a Java generic Maven project, and we're going to add the MyEclipse Web Project feature to it.

Select Project-->myeclipse-->project capabilities-->add Web Project Capabilites, set the parameters in the pop-up window as follows, then select Yes in the next pop-up window. So our project is Web engineering (notice that the project icon is changed, and MyEclipse automatically relies on Jee's package).


6. Configure the project properties, open the Project Properties panel ---This step is very important, are some of the details of the configuration, indispensable ah

1) Java Build Path

1> Source

Add Src/main/java, Src/test/java, src/test/resources as the source folder, there is no need to detail it, click "Add Folder" on the line.

The "Default output folder" of the minimum face is modified to "mywebapp/src/main/webapp/web-inf/classes"---this is important.

Modify the output directory of these source folders, where Main/java and main/resources output to the default output folder, while Test/java and test/resources output to target/ Test-classes, (How to modify the---click on the output Folder under each node, then click on the right of the Edit button on the line) the final setting results are as follows:


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.