flink的jar包和服务器的包冲突解决方案

1,因本地依赖的包和服务器上包冲突。主要是是flink集群已经有guava的jar包。错误代码如下:


2020-12-04 23:35:45
java.lang.NoSuchMethodError: com.google.common.hash.Hashing.farmHashFingerprint64()Lcom/google/common/hash/HashFunction;
	at com.dewu.com.aliyun.openservices.aliyun.log.producer.internals.Utils.generateProducerHash(Utils.java:31)
	at com.dewu.com.aliyun.openservices.aliyun.log.producer.LogProducer.<init>(LogProducer.java:91)
	at com.poizon.userportrait.sink.redis.UserPortraitRedisSink.open(UserPortraitRedisSink.java:123)
	at com.alibaba.blink.streaming.connector.custom.sink.CustomOutputFormat.open(CustomOutputFormat.java:70)
	at com.alibaba.blink.streaming.connectors.common.output.TupleOutputFormatAdapterSink.open(TupleOutputFormatAdapterSink.java:51)
	at org.apache.flink.api.common.functions.util.FunctionUtils.openFunction(FunctionUtils.java:36)
	at org.apache.flink.streaming.api.operators.AbstractUdfStreamOperator.open(AbstractUdfStreamOperator.java:102)
	at org.apache.flink.streaming.api.operators.StreamSink.open(StreamSink.java:48)
	at org.apache.flink.streaming.runtime.tasks.StreamTask.openAllOperators(StreamTask.java:527)
	at org.apache.flink.streaming.runtime.tasks.StreamTask.lambda$invoke$1(StreamTask.java:386)
	at org.apache.flink.util.checkpointlock.SynchronizedLockHelper.lockAndRun(SynchronizedLockHelper.java:51)
	at org.apache.flink.util.checkpointlock.CheckpointLockDelegate.lockAndRun(CheckpointLockDelegate.java:52)
	at org.apache.flink.streaming.runtime.tasks.StreamTask.invoke(StreamTask.java:380)
	at org.apache.flink.runtime.taskmanager.Task.run(Task.java:736)
	at java.lang.Thread.run(Thread.java:834)

2,通过maven的插件,relocation重定义类目即可解决问题。maven配置如下:


 <executions>
    <execution>
        <phase>package</phase>
        <goals>
            <goal>shade</goal>
        </goals>
        <configuration>
            <relocations>
                <relocation>
                    <pattern>com.aliyun.openservices.aliyun.log.producer</pattern>
                    <shadedPattern>com.xxxx.com.aliyun.openservices.aliyun.log.producer</shadedPattern>
                </relocation>
                <relocation>
                    <pattern>com.google.common</pattern>
                    <shadedPattern>com.xxxx.com.google.common</shadedPattern>
                </relocation>
            </relocations>
        </configuration>
    </execution>
</executions>

或者其他方式


			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>
				<version>3.3.0</version>
				<configuration>
					<skipTests>true</skipTests>
				</configuration>
				<executions>
					<execution>
						<id>make-assembly</id>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
						<configuration>
							<relocations>
								<relocation>
									<pattern>net.jpountz.lz4</pattern>
									<shadedPattern>com.vipshop.net.jpountz.lz4</shadedPattern>
								</relocation>
							</relocations>
						</configuration>
					</execution>
				</executions>

			</plugin>

3,注意,上传jar的时候,不能使用带dependencies.jar的包,就用原生的即可

参考从定向类

Apache Maven Shade Plugin – Relocating Classes

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值