链接地址:[Selecting Contents for Uber JAR](http://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html)

apache网站在国内打开太慢了。因此我将这些有用的资源收集起来,保存在博客中!

Apache Maven Shade Plugin:是一个Maven打包的插件。其官网英文定义如下:This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade

001.

  1. <project>
  2. ...
  3. <build>
  4. <plugins>
  5. <plugin>
  6. <groupId>org.apache.maven.plugins</groupId>
  7. <artifactId>maven-shade-plugin</artifactId>
  8. <version>2.4.3</version>
  9. <executions>
  10. <execution>
  11. <phase>package</phase>
  12. <goals>
  13. <goal>shade</goal>
  14. </goals>
  15. <configuration>
  16. <artifactSet>
  17. <excludes>
  18. <exclude>classworlds:classworlds</exclude>
  19. <exclude>junit:junit</exclude>
  20. <exclude>jmock:*</exclude>
  21. <exclude>*:xml-apis</exclude>
  22. <exclude>org.apache.maven:lib:tests</exclude>
  23. <exclude>log4j:log4j:jar:</exclude>
  24. </excludes>
  25. </artifactSet>
  26. </configuration>
  27. </execution>
  28. </executions>
  29. </plugin>
  30. </plugins>
  31. </build>
  32. ...
  33. </project>

002.

  1. <project>
  2. ...
  3. <build>
  4. <plugins>
  5. <plugin>
  6. <groupId>org.apache.maven.plugins</groupId>
  7. <artifactId>maven-shade-plugin</artifactId>
  8. <version>2.4.3</version>
  9. <executions>
  10. <execution>
  11. <phase>package</phase>
  12. <goals>
  13. <goal>shade</goal>
  14. </goals>
  15. <configuration>
  16. <filters>
  17. <filter>
  18. <artifact>junit:junit</artifact>
  19. <includes>
  20. <include>junit/framework/**</include>
  21. <include>org/junit/**</include>
  22. </includes>
  23. <excludes>
  24. <exclude>org/junit/experimental/**</exclude>
  25. <exclude>org/junit/runners/**</exclude>
  26. </excludes>
  27. </filter>
  28. <filter>
  29. <artifact>*:*</artifact>
  30. <excludes>
  31. <exclude>META-INF/*.SF</exclude>
  32. <exclude>META-INF/*.DSA</exclude>
  33. <exclude>META-INF/*.RSA</exclude>
  34. </excludes>
  35. </filter>
  36. </filters>
  37. </configuration>
  38. </execution>
  39. </executions>
  40. </plugin>
  41. </plugins>
  42. </build>
  43. ...
  44. </project>

003.

  1. <project>
  2. ...
  3. <build>
  4. <plugins>
  5. <plugin>
  6. <groupId>org.apache.maven.plugins</groupId>
  7. <artifactId>maven-shade-plugin</artifactId>
  8. <version>2.4.3</version>
  9. <executions>
  10. <execution>
  11. <phase>package</phase>
  12. <goals>
  13. <goal>shade</goal>
  14. </goals>
  15. <configuration>
  16. <minimizeJar>true</minimizeJar>
  17. </configuration>
  18. </execution>
  19. </executions>
  20. </plugin>
  21. </plugins>
  22. </build>
  23. ...
  24. </project>

004.

  1. <project>
  2. ...
  3. <build>
  4. <plugins>
  5. <plugin>
  6. <groupId>org.apache.maven.plugins</groupId>
  7. <artifactId>maven-shade-plugin</artifactId>
  8. <version>2.4.3</version>
  9. <executions>
  10. <execution>
  11. <phase>package</phase>
  12. <goals>
  13. <goal>shade</goal>
  14. </goals>
  15. <configuration>
  16. <minimizeJar>true</minimizeJar>
  17. <filters>
  18. <filter>
  19. <artifact>log4j:log4j</artifact>
  20. <includes>
  21. <include>**</include>
  22. </includes>
  23. </filter>
  24. <filter>
  25. <artifact>commons-logging:commons-logging</artifact>
  26. <includes>
  27. <include>**</include>
  28. </includes>
  29. </filter>
  30. </filters>
  31. </configuration>
  32. </execution>
  33. </executions>
  34. </plugin>
  35. </plugins>
  36. </build>
  37. ...
  38. </project>

(001)`Shade`官网上的介绍也不多。可能因为其相对比较简单吧。但是,我这个菜鸟仍然很头疼如何配置`Shade`。网上的资料比较少,估计也是认为比较简单吧,没人撰文详细介绍`Shade`。所以,官方提供的例子就成为最有价值的资料了。

(002)结合`Shade`源码,我开始踏上研究如何使用的`Shade`旅程。源码的获得比较简单,为了研究`Shade`可以将其添加到pom.xml的`dependencies`中。当然也可以去官网镜像下载

(003)研究任何`Maven Plugin`之前,都应该先看看这篇插件的介绍 [Guide to Configuring Plug-ins](http://maven.apache.org/guides/mini/guide-configuring-plugins.html),这会让你少走很多弯路(我不会告诉你我是掉坑里了爬起来才知道的)。

(003001)在这篇官方文档里,我首次看到了`Mojo`,这是Maven Plugin使用的一个IOC框架。(当下我并没有去研究Mojo所以知道的有限也许未来会去研究下。有兴趣的朋友可以去搜索下。)

(003002)`Mojo`中的字段是和plugin中的配置对应的,如果对例子中的配置很疑惑,就可以翻开源码中的`Mojo`顺藤摸瓜,找到它们的原理。`Shade`中的`Mojo`就是`ShadeMojo.java`了。

(004)end.

[Apache Maven Shade Plugin] [example] [001] 官方例子:includes-excludes的更多相关文章

  1. 施用 maven shade plugin 解决 jar 或类的多版本冲突

    施用 maven shade plugin 解决 jar 或类的多版本冲突   使用 maven shade plugin 解决 jar 或类的多版本冲突java 应用经常会碰到的依赖的三方库出现版本 ...

  2. maven shade插件小记

    maven shade plugin插件小用 项目中一直使用assembly插件来整合依赖包到一个胖jar,在做这个akka http项目的时候,在scala ide的run/debug中都执行正常, ...

  3. maven Error resolving version for plugin 'org.apache.maven.plugins:maven-eclipse-plugin' from the repositories 解决

    报错:Error resolving version for plugin 'org.apache.maven.plugins:maven-eclipse-plugin' from the repos ...

  4. CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved

    CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin ...

  5. Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5

    Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of ...

  6. maven install 报错Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin

    Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of ...

  7. Maven命令行创建web项目,并部署到jobss当中(解决No plugin found for prefix 'jboss-as' in the current project and in the plugin groups [org.apache.maven.plugins,问题)

    首件创建项目:此处可参照:http://maven.apache.org/guides/mini/guide-webapp.html mvn archetype:generate -DgroupId= ...

  8. Eclipse使用Maven,创建项目出现:Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resour

    使用maven创建简单的项目时候经常会遇到 Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resource ...

  9. eclipse导入maven项目时报Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources

    在用Eclipse IDE for Java EE Developers进行maven项目的开发时,报错Could not calculate build plan: Plugin org.apach ...

随机推荐

  1. ios开发——实用技术篇&应用间跳转

    应用之间的跳转 说明:本文介绍app如何打开另一个app,并且传递数据. 一.简单说明 新建两个应用,分别为应用A和应用B. 实现要求:在appA的页面中点击对应的按钮,能够打开appB这个应用. 1 ...

  2. Unity3d截图保存到Android相册的实现

    Unity3d截图保存到Android相册的实现-----------------------------ultrasoon 季风原创--------------------------------- ...

  3. linux下的十六进制编辑器---wxHexEdit

    ....其实wxHexEdit是一个跨平台的十六进制编辑器,支持windows,linux,mac. 之所以标题用linux...是因为windows下多数都用winhex,UE之类的编辑器,而lin ...

  4. HDU 4605 Magic Ball Game 树状数组

    题目大意很简单. 有一颗树(10^5结点),所有结点要么没有子结点,要么有两个子结点.然后每个结点都有一个重量值,根结点是1 然后有一个球,从结点1开始往子孙结点走. 每碰到一个结点,有三种情况 如果 ...

  5. git的.gitignore配置

    .gitignore 配置文件用于配置不需要加入版本管理的文件,配置好该文件可以为我们的版本管理带来很大的便利,以下是个人对于配置 .gitignore 的一些心得. 1.配置语法: 以斜杠“/”开头 ...

  6. 基于ARM-LINUX的温度传感器驱动-DS18B20

    转载:http://blog.csdn.net/ayangke/article/details/6883244 作者:冯建,华清远见嵌入式学院讲师. DS18B20数字温度传感器接线方便,封装成后可应 ...

  7. mysql ERROR1405 access deny 问题解决

    sudo /usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking 使用这条命令可以跳过开 ...

  8. CEP简介

    CEP即Complex Event Processing缩写,翻译过来就是复杂事件处理(复合事件可能更加准确).   1.为什么我们需要CEP?CEP是具有实时分析以及快速响应等等功能.下面让我们通过 ...

  9. 【Shell脚本学习3】什么时候使用Shell

    因为Shell似乎是各UNIX系统之间通用的功能,并且经过了POSIX的标准化.因此,Shell脚本只要“用心写”一次,即可应用到很多系统上.因此,之所以要使用Shell脚本是基于: 简单性:Shel ...

  10. iOS - UI - UIWebView

    1.UIWebView UIWebView 是 苹果提供的用来展示网页的UI控件.它也是最占内存的控件. iOS8.0 webkit框架. WKWebView,相比UIWebView,节省了1/3~1 ...