Using Maven to manage web projects under MyEclipse

1. Create or use a synchronization tool such as svn to checkout to a local maven-managed web project.

To create a method, use the command in a directory: mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp. Enter the corresponding parameters according to the prompts, the intermediate process is as follows

 

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
 And: : And
....
[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 in the folder. The project's folder root directory is "mywebapp" (please see the above process), and the structure of the directory is

 

mywebapp
     + --- pom.xml
     +---src
           +---main
                  +---resources
                  +---webapp
                            +---index.jsp
                            +---WEB-INF
                                       + --- web.xml

                 

Completing the directory structure of the project, the maven project directory generated in step 1 is incomplete, such as our java code, our test directory, etc., which are now manually created and completed as follows

mywebapp
     + --- pom.xml
     +---src
           +---main
                  +---resources
                  + --- java << Addition
                  +---webapp
                            +---index.jsp
                            +---WEB-INF
                                       + --- web.xml
           +---test << add
                  +---resources << add
                  + --- java << Addition
     +---target <<eclipse added automatically
           +---classes <<eclipse added automatically
           +---test-classes <<eclipse added automatically

 

screenshot:


Increase the Web Project function of MyEclipse

So far, we have only imported a Maven webapp into MyEclipse. However, in MyEclipse, this is just an ordinary Java Maven project. In this step, we will 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, and then select yes in the next pop-up window. In this way, our project is a web project (note that the project icon has changed, and MyEclipse automatically depends on the JEE package).


 

Configure the project properties and open the project properties panel ---this step is very important, it is all detailed configuration, and it is indispensable.

1) Java Build Path

1> Source

Add src/main/java, src/test/java, src/test/resources as the source folder, no need to elaborate here, just click "add folder".

The "default output folder" of the minimal facet is changed to "mywebapp/src/main/webapp/WEB-INF/classes"---this is very important

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

 

 

2> Order And Export

In order to display good-looking, adjust the display order, without going into details, it is very simple, see the following picture:

 

 

2)Java Compiler

Note that in the above picture, my project shows that the jdk is 1.4, so we need to modify it to the version we want, which is not detailed here, and should be changed.

 
3) Myeclipse-->Web
This one is used to modify the web features of the settings project, as shown below:
 

Well, a MyEclipse Web Project + Maven webapp project is built. The rest is to develop and debug the web in myeclipse and finally package it with maven. Of course, the dependency feature of maven must be used (add the jar package to be depended on directly in pom.xml, and then refresh the project and it will be imported automatically).

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327065524&siteId=291194637