给war包添加静态资源路径(配置多个web静态资源路径)
maven-war-plugin:webResources.resource.directory
可以配置多个 resource,每个resource都可以配置 排除或包含文件(includes 和 excludes)。
如下例所示:
<!-- 打war包 -->
< plugin >
< artifactId >maven-war-plugin</ artifactId >
< version >2.1.1</ version >
< executions >
< execution >
< id >default-war</ id >
< phase >package</ phase >
< goals >
< goal >war</ goal >
</ goals >
</ execution >
</ executions >
< configuration >
<!-- 把war里面的class当成附件打成一个jar包 -->
< attachClasses >true</ attachClasses >
< webResources >
<!-- 资源1:包含对应静态资源文件,默认会拷贝到web root目录下 -->
< resource >
< directory >D:/C/dev-solft/tomcat-7.0/zoa</ directory >
</ resource >
<!-- 资源2:包含对应静态资源文件 -->
< resource >
< directory >${basedir}/ext-resources/local</ directory >
< includes >
< include >**/*.jpg</ include >
< include >**/*.vm</ include >
</ includes >
< excludes >
< exclude >*pattern3/pattern3</ exclude >
< exclude >pattern4/pattern4</ exclude >
</ excludes >
<!--By default web resources are copied to the root of the WAR -->
<!-- override the destination directory for this resource -->
< targetPath >WEB-INF</ targetPath >
</ resource >
</ webResources >
</ configuration >
</ plugin >
|
具体参见:
http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html
- (点击以下标题隐藏正文内容)
配置多个resource路径
批量引入本地lib目录下的jar包或任何资源
方法应该不止一种,下面介绍这种方法比较方便,在pom.xml里面配置即可:
build:resources.resource. directory / targetPath
< build >
< finalName >${release-name}</ finalName >
< sourceDirectory >${basedir}/src/main/java</ sourceDirectory >
< outputDirectory >${basedir}/src/main/webapp/WEB-INF/classes</ outputDirectory >
< resources >
< resource >
< directory >${basedir}/src/main/resources</ directory >
< excludes >
< exclude >*.copyarea.db</ exclude >
</ excludes >
</ resource >
< resource >
< directory >${basedir}/lib</ directory >
< targetPath >${basedir}/src/main/webapp/WEB-INF/lib</ targetPath >
</ resource >
</ resources >
|
- (点击以下标题隐藏正文内容)
Maven打war包时排除不想打包的静态资源文件
warSourceExcludes
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-war-plugin</ artifactId >
< configuration >
<!-- 把war里面的class当成附件打成一个jar包 -->
< attachClasses >true</ attachClasses >
< warSourceExcludes >**/.copyarea.db</ warSourceExcludes >
</ configuration >
</ plugin >
|
注意,和以下两个的区别:
<dependentWarExcludes> 和 <webResources>
具体可以查看官方手册。
- (点击以下标题隐藏正文内容)
Maven打war包时,不导入jar文件(lib下为空)、排除指定jar包
maven-war-plugin:packagingExcludes
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-war-plugin</ artifactId >
< configuration >
<!-- 把war里面的class当成附件打成一个jar包 -->
< attachClasses >true</ attachClasses >
< warSourceExcludes >**/.copyarea.db</ warSourceExcludes >
< packagingExcludes >WEB-INF/lib/*.jar</ packagingExcludes >
</ configuration >
</ plugin >
|
- (点击以下标题隐藏正文内容)
打包源代码时排除某些文件
maven-source-plugin:configuration.excludes
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-source-plugin</ artifactId >
< version >2.1</ version >
< configuration >
< attach >true</ attach >
< source >1.6</ source >
< target >1.6</ target >
< encoding >UTF-8</ encoding >
</ configuration >
< executions >
< execution >
< id >attach-sources</ id >
< phase >verify</ phase >
< goals >
< goal >jar-no-fork</ goal >
</ goals >
< configuration >
< excludes >
< exclude >**/.copyarea.db</ exclude >
< exclude >**/*.keep</ exclude >
< exclude >**/*.bak</ exclude >
</ excludes >
</ configuration >
</ execution >
</ executions >
</ plugin >
|
- (点击以下标题隐藏正文内容)
将依赖打入source源码包
maven-source-plugin:execution.<goal>aggregate</goal>
< plugin >
< artifactId >maven-source-plugin</ artifactId >
< configuration >
< attach >true</ attach >
</ configuration >
< executions >
< execution >
< phase >package</ phase >
< goals >
<!-- 将依赖打入source包 -->
< goal >aggregate</ goal >
</ goals >
</ execution >
</ executions >
</ plugin >
|
- (点击以下标题隐藏正文内容)
合并打包:将所有依赖的jar包打包在一起、打包成一个jar包
方法一:maven-shade-plugin(推荐)
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-shade-plugin</ artifactId >
< version >2.3</ version >
< executions >
< execution >
< phase >package</ phase >
< goals >
< goal >shade</ goal >
</ goals >
< configuration >
< shadedArtifactAttached >true</ shadedArtifactAttached >
< shadedClassifierName >ALL</ shadedClassifierName >
</ configuration >
</ execution >
</ executions >
</ plugin >
|
方法二:maven-assembly-plugin
< build >
< plugins >
< plugin >
< artifactId >maven-assembly-plugin</ artifactId >
< configuration >
< archive >
< manifest >
< mainClass >com.zollty.maven.Main</ mainClass >
</ manifest >
</ archive >
< descriptorRefs >
< descriptorRef >jar-with-dependencies</ descriptorRef >
</ descriptorRefs >
</ configuration >
</ plugin >
</ plugins >
</ build >
|
例2:
< plugin >
< artifactId >maven-assembly-plugin</ artifactId >
< configuration >
< appendAssemblyId >false</ appendAssemblyId >
< descriptorRefs >
< descriptorRef >jar-with-dependencies</ descriptorRef >
</ descriptorRefs >
< archive >
< manifest >
< mainClass >com.zollty.util.Main</ mainClass >
</ manifest >
</ archive >
</ configuration >
< executions >
< execution >
< id >make-assembly</ id >
< phase >package</ phase >
< goals >
< goal >assembly</ goal >
</ goals >
</ execution >
</ executions >
</ plugin >
|
运行下面的指令:
assembly:assembly
- (点击以下标题隐藏正文内容)
强制排除Jar包依赖(包括传递的依赖)
用maven-enforcer-plugin检查,当发现有依赖的jar包则构建失败
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-enforcer-plugin</ artifactId >
< executions >
<!-- <execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>2.1.0</version>
</requireMavenVersion>
<requireJavaVersion>
<version>1.6</version>
</requireJavaVersion>
</rules>
</configuration>
</execution> -->
< execution >
< id >enforce-banned-dependencies</ id >
< goals >
< goal >enforce</ goal >
</ goals >
< configuration >
< rules >
< bannedDependencies >
< excludes >
<!-- <exclude>junit:junit</exclude> -->
< exclude >org.slf4j:slf4j-api</ exclude >
< exclude >commons-logging:commons-logging</ exclude >
</ excludes >
<!-- <includes>
<include>junit:junit:4.8.2:jar:test</include>
<include>cglib:cglib-nodep:jar:2.2</include>
</includes> -->
</ bannedDependencies >
</ rules >
< fail >true</ fail >
</ configuration >
</ execution >
</ executions >
</ plugin >
|
Maven资源排除和包含相关推荐
- Maven打包排除某个资源或者目录
最近在spark streaming本地调试的时候,引入了一些资源文件,打包的时候需要给排除掉.所以就考虑使用maven的方式 详细参考官方文档:https://maven.apache.org/pl ...
- maven 打包排除指定文件
maven 打包排除指定文件 2015-10-16 13:57 3197人阅读 评论(0) 收藏 举报 分类: maven(16) 记一次我对maven深刻变革的认知. 当我还不知道Ma ...
- maven 上传jar 包含源码
2019独角兽企业重金招聘Python工程师标准>>> maven 上传jar 包含源码 1.pom配置如下 <build><plugins><!-- ...
- 使用Maven在jar中包含依赖项
本文翻译自:Including dependencies in a jar with Maven Is there a way to force maven(2.0.9) to include all ...
- Maven打jar包包含源代码
Maven打jar包包含源代码 Maven打jar包包含源代码只需要在pom.xml 中配置如下插件即可 <plugin><groupId>org.apache.maven.p ...
- maven资源过滤导致打包后文件变大
今天遇到一个问题,我们有个ip.dat二进制文件,通过里面内容可以解析ip所在的地域信息,本地单元测试都是OK的,部署到测试环境后,发现解析ip的时候报错.拿测试环境打印出的IP地址,在本地单元测试也 ...
- Maven依赖排除 禁止依赖传递 取消依赖的方法
大家都知道Maven的优点是依赖管理,特别是前期使用ANT的开发者都有很多感触.最近要开发一个java工程,定的要使用maven,会使用hadoop和hbase的客户端,而引入一个hadoop-cli ...
- maven如何排除依赖
maven具有依赖性,就比如说你添加了一个依赖,然后那个依赖的依赖也会添加.如果你不想添加那个依赖,可以排除它!!! 如何查看依赖jar包的依赖关系呢? <dependency> < ...
- YCM(YouCompleteMe)资源下载,包含了全部的插件及依赖子模块
为了解决大部分人没有vpn,下载ycm及其他插件速度慢的问题,特此上传了资源,有需要的可自行下载. 本资源包含了**"手把手教你配置linux下C++开发工具--vim+ycm(YouCom ...
最新文章
- 翻译BonoboService官网的安装教程
- 提升开发效率的一款mybatis开发神器
- python:自动化测试 playwright 库上传和下载
- Windbg+Vmware/VirutalBox内核调试加速工具VirtualKD
- 言有三新书预售,不贵,有料
- 高计能计算要实现软着陆
- Qt工作笔记-QMainWindow自定义窗体中利用状态栏进行窗体放缩
- 很详细的硬盘基础知识
- 灾难恢复! 关于做过快照的AVHD文件合并成VHD .
- fatal io error 11错误
- Windows网络编程(基础篇1)
- 21.	SCHEMATA
- python-房贷内部收益率计算
- Anton and Chess
- python实训day1
- 百度token怎么获取_【专栏精选】实战:百度语音识别
- 数值计算——最小二乘拟合二元一次多项式
- 负值最大与 Alpha-Beta 剪枝的结合
- LinkedHashMap对key进行排序
- 干货 | 数据治理落地难?携程度假数据治理需求设计实践
热门文章
- Ubuntu 16.04 LTS将移除私有的AMD催化剂驱动
- 移动应用众测之“Bug探索测试”实战
- Pascal语言简介
- cocos creator2.1.3 仙剑奇侠传单机版源码
- Raspberry pi音乐播放器omxplayer
- [Origin]三维柱状图绘制
- 精读Translating and Segmenting Multimodal Medical Volumes with Cycle- andShape-Consistency Generative
- 土巴兔上市再折戟,互联网家装没故事
- 5w1h分析数据异常问题
- stm32电子秤diy制作_魅力状元丨龙腾社区举办手工口红DIY活动