eclipse build maven-web project

 

First, build the file structure of the maven project

Start with the most commonly used basic project file structure and establish the following directory structure:

selfproject
---nutrition
    ---src
        ---main
            ---java
            ---resources
            ---webapp
                ---WEB-INF
                    ---web.xml
        ---test
            ---java
            ---resources
    ---pom.xml
---service
    ---src
        ---main
            ---java
            ---resources
            ---webapp
                --- WEB- INF
                     --- web.xml
         --- test
             --- java
             --- resources
     --- pom.xml
 --- pom.xml
View Code

Second, the initial pom file structure

1. Contents of the pom file under selfproject:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.selfproject.nutrition</groupId>
  <artifactId>selfproject-root</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <name>selfproject</name>
  <packaging>pom</packaging>
  <modules>
      <module>nutrition</module>
      <module>service</module>
  </modules>
  <dependencies>
  </dependencies>
</project>
View Code

 

2. Contents of pom file under nutrition:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.selfproject.nutrition</groupId>
    <artifactId>selfproject-root</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>
  <artifactId>selfproject-nutrition</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>selfproject-nutrition Maven Webapp</name>
</project>
View Code

 

3. Contents of pom file under service:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.selfproject.nutrition</groupId>
    <artifactId>selfproject-root</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>
  <artifactId>selfproject-service</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>selfproject-service Maven Webapp</name>
</project>
View Code

 

3. Eclipse loads the built maven project

1. Project import

Right-click "import" under Maven "select Existing Maven Projects" next step "select the file root directory selfproject just built" select Finish, and maven will be loaded as eclipse as shown below:

Select the imported project (the options in the projects in the figure should be selected):

2. After completing the imported project:

 3. Configure the servers server

Then configure the tomcat server in eclipse. If there is no tab item for servers, search for "servers" in Window"Show View"Others, then select and click OK, right-click in servers"new"server", select tomcat 6.0, and then configure the association The path of the local tomcat. The screenshot of the operation is as follows:

4. Eclipse deploys web projects

After configuring the servers, right-click the configured service and select "Add and Remove", and you will find that there is no desired optional web project in the pop-up selection box. Find the reason. The previously imported maven project has no corresponding web configuration file. By default, eclipse is loaded in the way of project. At this time, the project should be converted into a web project.

Select the project > right click > Properties > ProjectFacets > click Convert to faceted from.., and then make the following selections:

[Note]: WebContent is the path corresponding to the web configuration file of the previous non-maven project. In the maven project, we used to put the web file under src/main/webapp, so we changed the Content directory item to src/main/webapp.

For more detailed operations, please refer to: https://blog.csdn.net/l4432321/article/details/52049125

At this point, we can see the corresponding project in the deployment box in the server:

 

[Problems encountered during the build process]

1. When converting a web project, the version selected when selecting Dynamic Web Module should match that of the deployed servers, otherwise there will be a deployment conflict (this use case uses web version 2.5, server 6.0)

【References】

1. Convert eclipse project to web project operation:

https://blog.csdn.net/l4432321/article/details/52049125

2. Detailed explanation of maven's pom file:

https://www.cnblogs.com/kuoAT/p/6811613.html

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324998075&siteId=291194637