zoukankan      html  css  js  c++  java
  • maven打包插件maven-shade-plugin简单介绍

    作用:

    1、可以把依赖打入jar包,然后直接使用这个jar包,从而不用担心依赖问题

    2、通过设置MainClass,创建一个可以执行的jar包

    3、Java工程经常会遇到第三方 Jar 包冲突,使用 maven shade plugin 可以解决 jar 或类的多版本冲突。 maven-shade-plugin 在打包时,可以将项目中依赖的 jar 包中的一些类文件打包到项目构建生成的 jar 包中,在打包的时候把类重命名

    3、Resource Transformers可以对多个依赖包的冲突内容进行处理

    Merging Content of Specific Files with AppendingTransformer, XmlAppendingTransformer and ResourceBundleAppendingTransformer

    Some jars contain additional resources (such as properties files) that have the same file name. To avoid overwriting, you can opt to merge them by appending their content into one file. One good example for this is when aggregating both the spring-context and plexus-spring jars. Both of them have the META-INF/spring.handlers file which is used by Spring to handle XML schema namespaces. You can merge the contents of all the files with that specific name using the AppendingTransformer as shown below:

    <project>
      ...
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
              <execution>
                <goals>
                  <goal>shade</goal>
                </goals>
                <configuration>
                  <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                      <resource>META-INF/spring.handlers</resource>
                    </transformer>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                      <resource>META-INF/spring.schemas</resource>
                    </transformer>
                  </transformers>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      ...
    </project>
    

    这篇文章的主要目的是:在做dubbo的jmeter压测的时候,你只需要把所有的依赖包打到dubbo-consumer的jar包里去,这样把这个唯一的jar包放入lib/ext下就可以了

    1、https://www.jianshu.com/p/7a0e20b30401

    2、https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#AppendingTransformer

  • 相关阅读:
    Eclipse集成Maven的Web工程demo(独立及Maven集成tomcat)
    Spring Boot的常见配置项解析
    SpringBoot入门demo
    简单句障碍的解决
    阅读理解(2000年统考)
    Java Web项目实战第1篇之环境搭建
    [STM32F10x] 利用定时器测量脉冲宽度
    [STM32F10x] 利用定时器测量频率
    STM32 输入捕获的脉冲宽度及频率计算
    RT-Thread—STM32—在线升级(Ymodem_OTA、HTTP_OTA)
  • 原文地址:https://www.cnblogs.com/shengulong/p/8386619.html
Copyright © 2011-2022 走看看