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

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

原文 http://blog.csdn.net/piankejingmo/article/details/79119909

2018-01-22 02:01:23阅读(655)

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

解决方法:将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




最新发布

CentOS专题

关于本站

5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!

小提示

按 Ctrl+D 键,
把本文加入收藏夹