Maven study concluded (7) - eclipse Maven is used to create Web project


Maven study concluded (seven) - eclipse Maven is used to create Web project


First, create a Web project

1.1 choose to create a Maven Project

  Select File -> New -> the Project , as shown below:

  

  In New selection window  Maven -> Maven Project . Click [ next] shown below:

  

 

1.2 Select Project Path

  According to the directory where the actual situation of the project to select an item, you can also select [Use default Workspace location] default workspace. As shown below:

  

Select the type of item 1.3

  In Artifact Id selection maven-archetype-webapp, as shown below:

  

1.4 Group ID and input and Artifact ID Package

  Group ID generally written large project name. Artifact ID is the name of the subproject.

  E.g. Spring a web package, Group ID : org.springframework , the artifactId : Spring-web .

  Package is the default you build a package, can not write. As shown below:

  

1.5 project file structure after the establishment of good

  File structure is set up immediately after the following diagram as shown in the following figure:

  

Second, the project will be automatically deployed to the Web server tomcat

2.1, tomcat server configuration file pom.xml

  Configure the web project pom.xml files, configuration is as follows:

Copy the code
 1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 2   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 3   <modelVersion>4.0.0</modelVersion>
 4   <groupId>me.gacl.maven</groupId>
 5   <artifactId>WebProject</artifactId>
 6   <packaging>war</packaging>
 7   <version>0.0.1-SNAPSHOT</version>
 8   <name>WebProject Maven Webapp</name>
 9   <url>http://maven.apache.org</url>
10   <dependencies>
11     <dependency>
12       <groupId>junit</groupId>
13       <artifactId>junit</artifactId>
14       <version>3.8.1</version>
15       <scope>test</scope>
16     </dependency>
17   </dependencies>
18   
19   <!-- 将Web项目自动部署到tomcat服务器的相关 配置信息-->
20   <build>
21       <!-- 将WebProject项目打包成WebProject.war自动部署到tomcat服务器的webapps目录下面 -->
22     <finalName>WebProject</finalName>
23     <plugins>
24           <plugin>
25               <groupId>org.codehaus.cargo</groupId>
26               <artifactId>cargo-maven2-plugin</artifactId>
27                 <version>1.2.3</version>
28                 <configuration>
29                     <container>
30                           <!-- 指明使用的tomcat服务器版本 -->
31                         <containerId>tomcat7x</containerId>
32                         <!--指明tomcat服务器的安装目录 -->
33                         <home>D:/apache-tomcat-7.0.53</home>
34                     </container>
35                     <configuration>
36                         <type>existing</type>
37                         <!--指明tomcat服务器的安装目录 -->
38                         <home>D:/apache-tomcat-7.0.53</home>
39                     </configuration>
40                 </configuration>
41                 <executions>  
42                   <execution>  
43                       <id>cargo-run</id>  
44                       <phase>install</phase>  
45                       <goals>  
46                           <goal>run</goal>  
47                       </goals>  
48                   </execution>  
49               </executions>
50           </plugin>
51       </plugins>
52   </build>
53 </project>
Copy the code

2.2, the web server publish a project to tomca webapps directory

  Web selected item (or items selected Web pom.xml file) → [Run As Maven install] → [], as shown below:

  

  After completion of the command execution] [Maven install, can be packaged into WebProject.war WebProject package item posted to tomca webapps directory server, as shown below:

  

  Test the deployed Web project, as shown below:

  

  Browser normal output the contents of index.jsp page, which shows our deployment successful. This is to use Maven in Eclipse project will be automatically deployed to the Web server tomcat process.

Reproduced in: https: //my.oschina.net/zhanghaiyang/blog/606199

Guess you like

Origin blog.csdn.net/weixin_33869377/article/details/92660166