这篇文章主要介绍了maven继承父工程统一版本号的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
一、建立一个maven工程 pom类型
统一管理依赖以及版本号
子工程不会使用所有的定义的依赖
子工程使用依赖时无需指定版本号
其pom.xml
4.0.0com.zhiyou.cyfenvironment0.0.1-SNAPSHOTpom<!-- 集中定义依赖版本号 --> 4.104.2.2.RELEASE3.2.81.2.21.2.155.1.471.6.42.4.21.0.94.3.51.22.52.02.53.3.21.3.2<!-- 管理jar包,不会引入 ,如果子工程需要哪些jar包,则具体地在子工程中引入,不过不需要写版本号--> <!-- 单元测试 --> junitjunit${junit.version}test<!-- Spring --> org.springframeworkspring-context${spring.version} org.springframeworkspring-beans${spring.version} org.springframeworkspring-webmvc${spring.version} org.springframeworkspring-jdbc${spring.version} org.springframeworkspring-aspects${spring.version}<!-- Mybatis --> org.mybatismybatis${mybatis.version} org.mybatismybatis-spring${mybatis.spring.version}<!-- MySql --> mysqlmysql-connector-java${mysql.version} org.slf4jslf4j-log4j12${slf4j.version}<!-- Jackson Json处理工具包 --> com.fasterxml.jackson.corejackson-databind${jackson.version}<!-- 连接池 --> com.jolboxbonecp-spring0.8.0.RELEASE<!-- httpclient --> org.apache.httpcomponentshttpclient${httpclient.version}<!-- JSP相关 --> jstljstl${jstl.version} javax.servletservlet-api${servlet-api.version}provided javax.servletjsp-api${jsp-api.version}provided<!-- 时间操作组件 --> joda-timejoda-time${joda-time.version}<!-- Apache工具组件 --> org.apache.commonscommons-lang3${commons-lang3.version} org.apache.commonscommons-io${commons-io.version} ${project.artifactId} <!-- 资源文件拷贝插件 --> org.apache.maven.pluginsmaven-resources-plugin2.7 UTF-8<!-- java编译插件 --> org.apache.maven.pluginsmaven-compiler-plugin3.2 1.81.8UTF-8 <!-- 配置Tomcat插件 --> org.apache.tomcat.maventomcat7-maven-plugin2.2
二、新创建一个maven工程
在pom.xml中,继承父工程,依赖去掉版本号
4.0.0<!-- 使用继承 --> com.zhiyou.cyfenvironment0.0.1-SNAPSHOTcom.zhiyou.cyfusermanage0.0.1-SNAPSHOTwar org.apache.poipoi3.10.1<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind --> com.fasterxml.jackson.corejackson-databind<!-- 时间操作组件 --> joda-timejoda-time<!-- spring-webmvc --> org.springframeworkspring-webmvc<!-- 切面 --> org.springframeworkspring-aspects<!-- spring的jdbc --> org.springframeworkspring-jdbc org.springframeworkspring-test4.3.7.RELEASE<!-- mysql的驱动 --> mysqlmysql-connector-java<!-- mybatis --> org.mybatismybatis<!-- mybatis于spring整合的jar --> org.mybatismybatis-spring<!-- generator --> org.mybatis.generatormybatis-generator-core1.3.5<!-- jstl --> javax.servletjstl1.2<!-- pagehelper --> com.github.pagehelperpagehelper5.1.2<!-- c3p0数据源 --> com.mchangec3p00.9.5.2<!-- --> javax.servletjavax.servlet-api3.1.0provided<!-- --> org.slf4jslf4j-log4j12<!-- https://mvnrepository.com/artifact/junit/junit --> junitjunittest<!-- 文件上传 --> commons-fileuploadco<strong style="color:transparent">来源gao@daima#com搞(%代@#码@网</strong>mmons-fileupload1.3.1 org.apache.shiroshiro-core1.4.0 org.apache.shiroshiro-web1.4.0 org.apache.shiroshiro-ehcache1.4.0 org.apache.shiroshiro-spring1.4.0
三、配置tomcat插件
在子工程pom.xml中继续添加
<!-- 配置tomcat插件 --> org.apache.tomcat.maventomcat7-maven-plugin<!-- tomcat配置 --> <!-- 端口号 -->8001<!-- 项目的路径 -->/
子工程邮件run as configurations ,点击左边的Maven Build新增配置
运行后,会发生以下错误
这时将父工程maven install,安装到本地仓库中,再运行则不报错
到此这篇关于maven继承父工程统一版本号的实现的文章就介绍到这了,更多相关maven继承父工程统一版本号内容请搜索gaodaima搞代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持gaodaima搞代码网!
以上就是maven继承父工程统一版本号的实现的详细内容,更多请关注gaodaima搞代码网其它相关文章!