Detailed configuration process of myeclipse + Maven WEB Project Development

Source: Internet
Author: User

Detailed configuration process of myeclipse + Maven WEB Project Development

I haven't done Web development for a long time. Today I suddenly want to get spring MVC, Because I recently learned something about Maven, so I want to use Maven for spring MVC Web framework, but the problem comes again. I have been using Maven in eclipse, and I have been using myeclipse for Web Development (I personally think that myeclipse is not convenient in eclipse, in myeclipse, Tomcat debugging can be used directly, which is very convenient). So how can I use both myeclipse and Maven? Today I wrote this article by turning it into a "trick.

 

Write it one step at a time:

 

1. Use Maven to create a webapp Project---- The reason is that Maven generally follows a certain directory structure. Although different directory structures can be used, you are not familiar with how to modify pom. XML files are used for the purpose, and modifying too many default configurations is not good for Maven.

Create method: Use the command MVN archetype: generate-darchetypeartifactid = Maven-Archetype-webapp in a directory. Follow the prompts to enter the corresponding parameters. The intermediate process is as follows:

 

C code
  1. D: \ study \ workspace4> MVN archetype: generate-darchetypeartifactid = Maven-Archetype-webapp
  2. [Info] scanning for projects...
  3. ....
  4. [Info] generating project in interactive mode
  5. Define value for property 'groupid': COM. xjd
  6. Define value for property 'artifactid': mywebapp
  7. Define value for property 'version': 1.0-snapshot ::
  8. Define value for property 'package': COM. xjd ::
  9. Confirm properties Configuration:
  10. Groupid: COM. xjd
  11. Artifactid: mywebapp
  12. Version: 1.0-Snapshot
  13. Package: COM. xjd
  14. Y: Y
  15. ....
  16. [Info] build success
  17. [Info] -----------------------------------------
  18. [Info] total time: 1: 46. 199 s
  19. [Info] finished at: Wed Nov 09 15:02:18 CST 2011
  20. [Info] final memory: 6 m/15 m
D:\study\workspace4>mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp[INFO] Scanning for projects.......[INFO] Generating project in Interactive modeDefine value for property 'groupId': : com.xjdDefine value for property 'artifactId': : mywebappDefine value for property 'version':  1.0-SNAPSHOT: :Define value for property 'package':  com.xjd: :Confirm properties configuration:groupId: com.xjdartifactId: mywebappversion: 1.0-SNAPSHOTpackage: 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

Finally, a Maven webapp project is created under the folder. "mywebapp" under the root directory of the project folder (check the process above). The structure of this directory is

 

Java code
  1. Mywebapp
  2. + --- Pom. xml
  3. + --- SRC
  4. + --- Main
  5. + --- Resources
  6. + --- Webapp
  7. + --- Index. jsp
  8. + --- WEB-INF
  9. + --- Web. xml
mywebapp     +---pom.xml     +---src           +---main                  +---resources                  +---webapp                            +---index.jsp                            +---WEB-INF                                       +---web.xml                 

 

2. Activate the maven plug-in for configuring myeclipse--- Myeclipse8.5 is used. It comes with a plug-in called maven4myeclipse. You only need to activate and configure it.

Activation Method: window --> preference --> myeclipse --> maven4myeclipse. Check the check box (enable mave4myeclipse features ).

Configuration method: There is a Maven node under the node opened by the activation method. Expand the node and configure the following two nodes:

Installations: this node uses the built-in Maven by default. We need to use the maven we installed, click "add", and add a Maven we installed externally. Check it after adding the node.

User settings: the default is under the user directory of drive C. m2/settings. XML file. here you need to configure the configuration file used by Maven for external installation, for example, CONF/settings under the maven installation directory. after selecting the XML file, do not forget to click the "update settings" button below.

 

3. Use myeclipse to import the project created by Maven:

There are two ways to import data:

1) follow these steps to import a project using myeclipse:

1> open dos and run: MVN Eclipse: Eclipse under the root directory of the project (mywebapp). After running: MVN Eclipse: Eclipse, two files are added to the project directory. classpath and. project, which is an Eclipse project file. Of course, myeclipse also recognizes

2> use the import function in myeclipse, select file --> Import... --> existing projects into workspace, select the project directory, and import

3> associate maven. The imported project is only a common Java project and will not be connected to the maven plug-in. Right-click the project --> maven4myeclipse --> enable dependency management, in this way, the project is associated with the maven plug-in (an m id is displayed in the upper-left corner of the root node of the project after Association ).

2) use Maven project in myeclipse to import data. The procedure is as follows:

1> use the import function in myeclipse, select file --> Import... --> existing Maven projects (different here), select the project directory, and import. --- Import here. myeclipse may update indexes online, which is very slow. We can cancel the update (click the red box on the Progress Panel). At this time, the project is imported, but this operation is not performed, for example, check the dependcy of Maven. In this case, perform step 1.

2> Update the project configuration, right-click the project --> maven4myeclipse --> Update project configuration

 

4. Complete the directory structure of the projectThe Maven project directory generated in step 1 is incomplete, such as our Java code, our test directory, etc., which is manually created and supplemented as follows:

 

C code
  1. Mywebapp
  2. + --- Pom. xml
  3. + --- SRC
  4. + --- Main
  5. + --- Resources
  6. + --- Java <add
  7. + --- Webapp
  8. + --- Index. jsp
  9. + --- WEB-INF
  10. + --- Web. xml
  11. + --- Test <add
  12. + --- Resources <add
  13. + --- Java <add
  14. + --- Target <automatically added by ECLIPSE
  15. + --- Classes <automatically added by ECLIPSE
  16. + --- Test-classes <automatically added by ECLIPSE
Mywebapp + --- pom. XML + --- SRC + --- main + --- resources + --- Java <add + --- webapp + --- index. JSP + --- WEB-INF + --- web. XML + --- test <add + --- resources <add + --- Java <add + --- target <eclipse automatically add + --- classes <eclipse automatically add + --- test-classes <automatically added by ECLIPSE

:

 

 

 

5. added the WEB Project function of myeclipse.

So far, we have only imported a Maven webapp to myeclipse. However, in myeclipse, this is just a Java normal Maven project, in this step, we need to add the WEB Project feature of myeclipse to it.

 

Select project --> myeclipse --> Project capabilities --> Add web project capabilites. In the pop-up window, set the parameters as follows, and then select Yes in the next pop-up window. In this way, our project is a web project (note that the project icon changes, and myeclipse automatically depends on the Jee package ).

 

 

6. Configure Project Properties and open the project properties panel.--- This step is very important. It's all about configuration details.

1) Java build path

1> Source

Add src/main/Java, src/test/Java, src/test/resources as source folder. You don't need to go into details here. Just click "add folder.

Minimal "Default Output Folder" changed to "mywebapp/src/main/webapp/WEB-INF/classes" --- this is important

Modify the output directory of these source folder, where main/Java and main/resources are output to default output folder, and test/Java and test/resources are output to target/test-classes, (how to modify --- click the Output Folder under each node, and then click the edit button on the right.) The final setting result is as follows:

 

2> order and export

To make the display look good, you can adjust the display sequence. It is very easy to look:

2) Java compiler

Note that in the image above, my project shows that JDK is 1.4, so to change it to the version we want, we will not detail it here, it should be changed.

3) myeclipse --> Web is used to modify the web features of the configuration project. For example, a project of myeclipse web project + Maven webapp is ready. The rest is to develop and debug the web in myeclipse and finally package it with Maven. Of course, you must use the maven dependency feature (directly put the jar package to be dependent on in pom. add in XML, and then refresh the project to automatically import ).

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.