Maven 精简依赖包
来源:互联网 发布:学生水杯推荐知乎 编辑:程序博客网 时间:2024/06/05 16:15
1、minijar
Maven的插件minijar,用于压缩依赖包。
minijar是mojo项目中的一个插件。
mojo项目:mojo.codehaus.org/
minijar项目:mojo.codehaus.org/minijar-maven-plugin/
该插件分析项目中类的依赖关系。
一般情况下项目并不是依赖库中的所有的类。
minijar能够生成一个项目依赖的相关类的迷你的jar文件版本。
比如一个依赖的jar文件有10个类,当前项目只直接/间接依赖其中的3个,那么minijar将为你生成一个只有3个类的jar。
简单使用
在默认target目录下生成mini jar文件:
这需要使用ueberjar,见:mojo.codehaus.org/minijar-maven-plugin/ueberjar-mojo.html
命令如下:
目前minijar已经不推荐使用了。该功能已经被包含在maven shade plugin中了。
<project> ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.0</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <artifactSet> <excludes> <exclude>classworlds:classworlds</exclude> <exclude>junit:junit</exclude> <exclude>jmock:*</exclude> <exclude>*:xml-apis</exclude> <exclude>org.apache.maven:lib:tests</exclude> <exclude>log4j:log4j:jar:</exclude> </excludes> </artifactSet> </configuration> </execution> </executions> </plugin> </plugins> </build> ...</project>
Of course, <includes> can be used as well to specify a white list of artifacts. Artifacts are denoted by a composite idenitifer of the form groupId:artifactId[[:type]:classifier]. Since plugin version 1.3, the wildcard characters '*' and '?' can be used to do glob-like pattern matching.
For fine-grained control of which classes from the selected dependencies are included, artifact filters can be used:
<project> ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.0</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <filters> <filter> <artifact>junit:junit</artifact> <includes> <include>junit/framework/**</include> <include>org/junit/**</include> </includes> <excludes> <exclude>org/junit/experimental/**</exclude> <exclude>org/junit/runners/**</exclude> </excludes> </filter> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> </configuration> </execution> </executions> </plugin> </plugins> </build> ...</project>
Here, Ant-like patterns are used to specify that from the dependency junit:junit only certain classes/resources should be included in the uber JAR. The second filter demonstrates the use of wildcards for the artifact identity which was introduced in plugin version 1.3. It excludes all signature related files from every artifact, regardless of its group or artifact id.
Besides user-specified filters, the plugin can also be configured to automatically remove all classes of dependencies that are not used by the project, thereby minimizing the resulting uber JAR:
<project> ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.0</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <minimizeJar>true</minimizeJar> </configuration> </execution> </executions> </plugin> </plugins> </build> ...</project>
As of version 1.6, minimizeJar will respect classes that were specifically marked for inclusion in a filter. Note that specifying an include filter for classes in an artifact implicitly excludes all non-specified classes in that artifact.
<project> ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.0</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <minimizeJar>true</minimizeJar> </configuration> <filters> <filter> <artifact>log4j:log4j</artifact> <includes> <include>**</include> </includes> </filter> <filter> <artifact>commons-logging:commons-logging</artifact> <includes> <include>**</include> </includes> </filter> </filters> </execution> </executions> </plugin> </plugins> </build> ...</project>
- Maven 精简依赖包
- Maven 精简依赖包
- 如何精简maven项目的依赖jar包
- Maven 包依赖
- Maven下载依赖包
- maven 导出依赖包
- maven依赖包查询
- maven依赖包 打包
- maven调入依赖包
- maven 依赖包形态
- maven包依赖冲突
- maven找到依赖包
- 排除依赖包,Maven
- maven工程依赖包导出
- maven 导出工程依赖包
- maven依赖包在线仓库
- maven工程依赖包导出
- maven依赖包的查询
- Android的Switch语句case expressions must be constant expressions错误的解决方法
- 开灯问题
- C 练习实例91-100
- jerry_shen的第一篇博客
- VS报错:”不允许对64位应用程序进行更改”,或者“Changes to 64-bit applications are not allowed.”
- Maven 精简依赖包
- 欢迎使用CSDN-markdown编辑器
- Hibernate实体类重名导致出错
- BUG
- zookeeper入门案例
- Bundle冗余分析
- 图像的插值算法之最近邻插值
- android面试题
- Jekins之——自动构建部署java maven项目(jdk1.7+tomcat7.0+jenkins2.19.3)