您的位置:首页 > 其它

maven的学习---创建web项目及继承概念(三)

2017-08-18 17:44 225 查看
使用maven创建一个web工程:

第一步:不选用骨架

第二步:打包方式选择为war

第三步:点击finish,工程创建成功

第四步:在工程中添加web.xml



web.xml内容如下:

<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_2_5.xsd" id="WebApp_ID" version="2.5">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
第五步:在webapp下创建index.jsp

第六步:运行tomcat插件:

tomcat:run:运行Tomcat6(默认)

tomcat7:run 运行tomcat7(推荐,但是需要添加插件)



<plugin>
    <!-- 配置插件 -->
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <configuration>
       <port>8080</port>
       <path>/</path>
    </configuration>
</plugin>

继承:

继承是为了消除重复,可以把很多相同的配置提取出来,例如:groupId,version等

第一步:创建父工程:



创建子工程:

创建方式有两种:

一种是创建新工程为子工程,在创建时设置父工程的GAV.

一种是修改原有的工程为子工程,在子工程的pom.xml文件中手动添加父工程的GAV。





现有工程继承父工程只需要在pom文件中添加parent节点即可

父工程统一依赖jar包

在父工程中对jar包进行依赖,在子工程中都会继承此依赖。





父工程统一管理版本号:

maven使用dependencyManagement管理依赖的版本号

注意:此处只是定义依赖jar包的版本号,并不实际依赖。如果子工程中需要依赖jar包还需要添加dependency节点。

父工程:





父工程中版本号的提取:

当父工程中定义的jar包越来越多,找起来越来越麻烦,所以可以把版本号提取成一个属性,集中 管理。



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: