Eclipse creates a new multi-module Maven project

1. File-->New-->Maven Project, create a simple project and customize the save path.

 

2. Click Next, specify the organization ID, project ID, project version, package type, and finally click Finish.

 

3. Right-click the project in the eclipse workspace, New-->Project-->Maven Module

 

4. The following dialog box appears, enter the module name

 

5. Specify the prototype for the new module, as shown below

 

6. Click Next to enter the overview dialog box shown in the figure below, confirm that there is no problem, and click Finish.

7. Create other maven modules in turn, mavenproject-dal module, mavenproject-service module.

8. The process of creating a web module is similar, but the prototype specified in step 5 is different, as shown in the figure below.

 

9. Open the mavenproject-web module and create a new java folder under the src/main folder.

10. Open the web.xml file and modify the content as follows.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    metadata-complete="true" version="3.0">
    <display-name>mavenproject-web</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

11. Deploy the mavenproject-web project to tomcat and visit http://localhost:8080/mavenproject-web to see the content presented on the home page.

Note: When creating a new maven project, eclipse will default the web version to 2.3 and the jdk to 1.5, which does not meet our requirements, so we need to configure the web and jdk versions by ourselves.

1. When right-clicking the project, Maven-->Update Project, the jre version referenced by the project will become 1.5, which may cause compilation errors.

Solution:

Option 1: Add the following code between the <project> tags in the pom.xml file of each module, specifying the jre version as 1.7

     <build>
         <plugins>
             <!-- define the project compile level -->
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <configuration>
                     <source>1.7</source>
                     <target>1.7</target>
                 </configuration>
             </plugin>
         </plugins>
     </build>

Option 2 (once and for all): Open the settings.xml file in maven's conf folder

Add the following code between <settings> tags and save settings.xml

<profiles>    
    <profile>  
    <id>jdk-1.7</id>  
    <activation>  
        <activeByDefault>true</activeByDefault>  
        <jdk>1.7</jdk>  
    </activation>  
    <properties>  
        <maven.compiler.source>1.7</maven.compiler.source>  
        <maven.compiler.target>1.7</maven.compiler.target>  
        <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>  
    </properties>  
    </profile>
</profiles>

Then go to eclispe-->Window-->Preferences-->Maven-->User Settings, click Update Settings on the right.

 

2. Modify the version of the web, right-click the web project-->Properties-->Project Facets, modify the version of the Dynamic Web Module to 3.0, and an error is displayed.

Solution:

(1) Open Window-->Show View-->Navigator window

(2) Select the file below and open it for editing

(3) Change jst.web from 2.3 to 3.0 and save it

(4) Go to Maven-->Update Project again, and find that no error is reported, then right-click the web project-->Properties-->Project Facets to check that the version of the web is already 3.0.

 

At this point, the multi-module maven project has been created, and the next is the detailed configuration of the pom.xml file, see the next article.

 

Guess you like

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