For a long time did not do web development, today suddenly want to get springmvc, because not long ago to learn a bit maven feel very good, so in SPRINGMVC this web framework want to use MAVEN to do, but the problem again, I have been in eclipse using Maven , and I used to do web development with MyEclipse (in Eclipse do web development personally think a little myeclipse convenient, in MyEclipse can directly use Tomcat debugging, is very convenient), So how to use both MyEclipse and Maven, today made a "tinkering", wrote this article.
Write it one step at a pace:
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 15:02:18 CST 2011
- [INFO] Final memory:6m/15m
Finally, under the folder created a Maven WebApp project, the project's folder root directory "MyWebApp" (see the above procedure), the structure of the directory is
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
:
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:
2> Order and Export
In order to show good-looking, adjust the display order, not elaborate, very simple, look:
2) Java Compiler
Notice the above picture, my project shows JDK is 1.4, so to change to the version we want, here is not detailed, should be changed.
3) Myeclipse-->web This one is used to modify the Web features of the setup project, such as:
Well, the project for a MyEclipse Web project + Maven WebApp is built. The rest is to develop and debug the Web in MyEclipse and finally use MAVEN to package, of course, use Maven's dependency feature (add the jar package that you want to rely on directly in Pom.xml, and then refresh the project to automatically import). The attachment is a created SPRINGMVC HelloWorld that can be used as a template. -------OK-------turn from: http://b-l-east.iteye.com/blog/1246482
MyEclipse + maven Developing a detailed configuration process for Web engineering