gpt4 book ai didi

java - 着色后 io.netty tcnative 停止工作

转载 作者:行者123 更新时间:2023-12-02 12:09:30 25 4
gpt4 key购买 nike

由于依赖项存在冲突,我想对 io.netty 进行遮蔽。着色后, native ssl 库 (netty-tcnative-boringssl-static) 的加载停止工作。

主 pom

我的主 pom 有此依赖项:

...
<dependency>
<groupId>com.example.myapp</groupId>
<artifactId>pubsub-library<artifactId>
<version>1.0</version>
</dependency>
...

进行着色的库

pubsub-library pom是这样的:

...
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>0.24.0-beta</version>
<dependency>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>io.netty</pattern>
<shadedPattern>com.example.myapp.shaded.io.netty</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
...

pubsub 具有以下 3 个依赖项:io.netty:netty-codec-http2:jar:4.1.14.Finalio.netty:netty-handler-proxy:jar: 4.1.14.Finalio.netty:netty-tcnative-boringssl-static:jar:2.0.3.Final

错误

当 io.netty.util.internal.NativeLibraryLoader 尝试加载 native 库时,就会出现问题。它给我错误,例如:

17:44:48.230 [main] DEBUG com.example.myapp.shaded.io.netty.util.internal.NativeLibraryLoader - -Dio.netty.tmpdir: /var/folders/ll/wy1vgf8945l_87mpfc9ylb94fglr7d/T (java.io.tmpdir)
17:44:48.230 [main] DEBUG com.example.myapp.shaded.io.netty.util.internal.NativeLibraryLoader - -Dio.netty.native.workdir: /var/folders/ll/wy1vgf8945l_87mpfc9ylb94fglr7d/T (io.netty.tmpdir)
17:44:48.241 [main] DEBUG com.example.myapp.shaded.io.netty.util.internal.NativeLibraryLoader - Unable to load the library 'com.example.myapp-shaded-netty-tcnative-osx-x86_64', trying other loading mechanism.
java.lang.UnsatisfiedLinkError: no com.example.myapp-shaded-netty-tcnative-osx-x86_64 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at com.example.myapp.shaded.io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.example.myapp.shaded.io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:311)
at java.security.AccessController.doPrivileged(Native Method)
at com.example.myapp.shaded.io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:303)
at com.example.myapp.shaded.io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:291)
at com.example.myapp.shaded.io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:224)
at com.example.myapp.shaded.io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:172)
at com.example.myapp.shaded.io.netty.handler.ssl.OpenSsl.loadTcNative(OpenSsl.java:423)
at com.example.myapp.shaded.io.netty.handler.ssl.OpenSsl.<clinit>(OpenSsl.java:91)
at com.example.myapp.job.audit.GoogleCloudCompatChecker.check(GoogleCloudCompatChecker.java:30)
at com.example.myapp.job.audit.AuditJobMain.main(AuditJobMain.java:8)

我查看了主 pom 生成的 jar 的内部。并且没有本地库与该名称匹配。这是在 META-INF/native 目录中:

libnetty-tcnative-linux-x86_64.so
libnetty-tcnative-osx-x86_64.jnilib
libnetty-transport-native-epoll.so
linux32
linux64
netty-tcnative-windows-x86_64.dll
osx
windows32
windows64

我做错了什么?如何在不破坏 tcnative 的情况下对 io.netty 进行着色。

最佳答案

看看NativeLibraryLoader source .

这可能与您使用的版本不同,但它表明它使用很少的启发式方法来查找 native 库,并且很可能这些启发式方法在阴影上失败,但可能很容易修复

仔细研究代码,也许会重写/调试/记录 NativeLibraryLoader。

您是否被迫使用某些依赖库的两个版本,以至于不能只使用 Maven 排除?

关于java - 着色后 io.netty tcnative 停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46650776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com