<导航

Intellij+maven:jar包冲突的解决方法(Hbase和Guava的冲突)

Hbase依赖的guava是12.0,程序中用到的guava是22.0,jar包冲突,总是报NoSuchMethod和ClassNoDef之类的错误

解决方法:

将冲突的一方第三方依赖包所有的依赖打包成一个整体。借用: maven-shade-plugin插件。

建立一个新的maven项目,将guava-22.0单独打成jar包,并改名,再重新放回源程序

1、guava单独打成jar包,并加入源程序的maven本地仓库

(1)、guava单独打成jar包的pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>Guava</groupId>
    <artifactId>guava</artifactId>
    <version>1.0</version>
 
<dependencies>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>22.0</version>
    </dependency>
</dependencies>
 
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern>com.google.guava</pattern>
                                    <shadedPattern>Guava.guava</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>com.google.common</pattern>
                                    <shadedPattern>Guava.common</shadedPattern>
                                </relocation>
                            </relocations>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" />
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
 
</project>

(2)打入源程序的maven本地仓库

mvn install:install-file -Dfile=XXX/guava-1.0.jar -DgroupId=Guava -DartifactId=guava -Dversion=1.0 -Dpackaging=jar

2、源程序引入新的guava-22.0jar包

<dependency>
      <groupId>Guava</groupId>
      <artifactId>guava</artifactId>
      <version>1.0</version>
    </dependency>

3、程序中引用新的guava

//import com.google.common.base.Charsets;
//import com.google.common.hash.BloomFilter;
//import com.google.common.hash.Funnel;
//import com.google.common.hash.PrimitiveSink;
 
import Guava.common.hash.BloomFilter;
import Guava.common.hash.Funnels;

注释部分是原来的import

 

文章整理自:

https://blog.csdn.net/piankejingmo/article/details/79119909

https://blog.csdn.net/m0_37125796/article/details/86149423

posted @ 2019-07-01 15:48  字节悦动  阅读(2101)  评论(0编辑  收藏  举报