maven打包插件详解
1|0maven-jar-plugin插件的使用及详解
该插件的xml配置及详解如下:
使用clean package命令打包成功后,目录结构如下所示:
打开meventest-0.0.1-SNAPSHOT.jar文件,查看打包成功后的项目结构
2|0maven-dependency-plugin插件的使用及详解
2|1简介
maven-dependency-plugin是处理与依赖相关的插件。它有很多可用的goal,大部分是和依赖构建、分析和解决相关的goal,这部分goal可以直接用maven的命令操作,例如:mvn dependency:tree、mvn dependency:analyze 。
但是我们最常用到的是 dependency:copy,dependency:copy-dependencies 及dependency:unpack ,dependency:unpack-dependencies 这四个。
2|2使用
插件声明:
dependency:copy
将一系列在此插件内列出的artifacts ,将他们copy到一个特殊的地方,重命名或者去除其版本信息。这个可以解决远程仓库存在但是本地仓库不存在的依赖问题,copy操作可以用来将某个(些)maven artifact(s)拷贝到某个目录下。添加phase和goal如下
比如把junit拷到libs目录下
执行mvn package打包命令之后,会多出libs目录
2|3dependency:unpack
unpack和copy类似,只不过它会把拷来的包解开,例如:
执行mvn package打包命令之后,slf4j复制到lib目录下,junit复制到libs目录下
junit和slf4j-log4j12拷完以后,放到lib和libs下的不再是Jar包,还是Jar包里的内容。
2|4copy-dependencies 和 unpack-dependencies
上面介绍的copy 和 unpack操作是由要拷某个包,这个包需要具体指定要拷哪个包,与当前工程的依赖没有关系。
copy-dependencies和它有点类似,但是它是用来拷当前工程的依赖包的,典型的,例如我们有一个web应用,当打成war包的时候,它所有的依赖也需要被打到应用中。
copy-dependencies的参数有很多,详细的可以参考:copy-dependencies Doc,但是几乎所有都有默认值。所以一个最简单的定义如下:
这里没有指定任何配置,所有的参数都用默认值,则当前工程的所有依赖(直接、间接的)都会被拷到target/dependency目录下。
也可以使用outputDirectory指定存放在。另外,以下几个参数可以控制哪些依赖将被拷出(或排除):
excludeArtifactIds | String |
2.0 |
Comma separated list of Artifact names to exclude. User property is: excludeArtifactIds . |
excludeClassifiers | String |
2.0 |
Comma Separated list of Classifiers to exclude. Empty String indicates don't exclude anything (default). User property is: excludeClassifiers . |
excludeGroupIds | String |
2.0 |
Comma separated list of GroupId Names to exclude. User property is: excludeGroupIds . |
excludeScope | String |
2.0 |
Scope to exclude. An Empty string indicates no scopes (default). User property is: excludeScope . |
excludeTransitive | boolean |
2.0 |
If we should exclude transitive dependencies Default value is: false . User property is: excludeTransitive . |
excludeTypes | String |
2.0 |
Comma Separated list of Types to exclude. Empty String indicates don't exclude anything (default). User property is: excludeTypes . |
includeArtifactIds | String |
2.0 |
Comma separated list of Artifact names to include. User property is: includeArtifactIds . |
includeClassifiers | String |
2.0 |
Comma Separated list of Classifiers to include. Empty String indicates include everything (default). User property is: includeClassifiers . |
includeGroupIds | String |
2.0 |
Comma separated list of GroupIds to include. User property is: includeGroupIds . |
includeScope | String |
2.0 |
Scope to include. An Empty string indicates all scopes (default). The scopes being interpreted are the scopes as Maven sees them, not as specified in the pom. In summary:runtime scope gives runtime and compile dependencies,compile scope gives compile, provided, and system dependencies,test (default) scope gives all dependencies,provided scope just gives provided dependencies,system scope just gives system dependencies. User property is: includeScope . |
includeTypes | String |
2.0 |
Comma Separated list of Types to include. Empty String indicates include everything (default). User property is: includeTypes . |
例如当前工程有以下依赖:
要排除所有scope为test的依赖:
注意:这里不能<excludeScope>test</excludeScope>
,这样会把所有compile级别的也排除。看下图:
Copied From: Dependencies Scopes
scope/phase-> | compile | test | run | assembly |
---|---|---|---|---|
compile | U | U | U | U |
provided | U | ! | ! | ! |
runtime | ! | U | U | U |
test | ! | U | ! | ! |
说明:最左侧是表示dependency的scope级别,顶行表示maven的阶段,可以看出:compile级别的dependency会在所有阶段都被使用。
要排除所有camel的依赖,如下:
要排除除camel-spring外的所有其他依赖如下:
3|0例子
3|1打包需求描述
1、导出单独的项目jar包(精简,不包含依赖jar)
2、项目依赖的所有jar包导出到lib目录下
3、项目依赖oracle ojdbc8.jar,假设在maven仓库中并不存在,需要一并导出并添加进MANIFEST.MF文件中的Class-Path。--也可以将ojdbc8安装到本地maven仓库后直接导出
3|2工程目录:
3|3maven pom.xml
__EOF__

本文链接:https://www.cnblogs.com/satire/p/14764582.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
2017-05-13 图书管理系统总结——分辨率适应