jna平台中的NoSuchMethodError [英] NoSuchMethodError in jna-platform
问题描述
我想发布该应用程序的新版本,但启动时会引发NoSuchMethodError
I wanna make a new release of the application but when starting it it throws NoSuchMethodError
java.lang.NoSuchMethodError: com.sun.jna.Native.load(Ljava/lang/String;Ljava/lang/Class;Ljava/util/Map;)Lcom/sun/jna/Library;
at com.sun.jna.platform.win32.Shell32.<clinit>(Shell32.java:45)
at com.sun.jna.platform.win32.Shell32Util.getFolderPath(Shell32Util.java:54)
at com.sun.jna.platform.win32.Shell32Util.getFolderPath(Shell32Util.java:71)
at com.faforever.client.preferences.PreferencesService.<clinit>(PreferencesService.java:78)
at com.faforever.client.FafClientApplication.main(FafClientApplication.java:55)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:85)
at com.exe4j.runtime.WinLauncher.main(WinLauncher.java:94)
at com.install4j.runtime.launcher.WinLauncher.main(WinLauncher.java:25)
类似于 使用JNA User32平台图的NoSuchMethodError 但是我确实有两个库的5.0.0版本.
Similar to NoSuchMethodError using JNA User32 platform map However I do have version 5.0.0 of both libaries.
有关此项目的信息 https://github.com/FAForever/downlords-faf-客户端它使用gradle作为构建工具...
It is about this project https://github.com/FAForever/downlords-faf-client it uses gradle as a build tool...
我还反编译了已安装的程序,并发现jna库中没有java声明的方法.我觉得这很奇怪.
Also I decompiled the installed program and found the method that java claims is not present in the jna libary. Which I find super weird.
我还要检查没有其他依赖项与jna有关.
Also I check no other dependency has a dependency on jna.
但是最奇怪的是,当我从intelij(oracle jdk 10)运行所有程序时,它可以工作,但是如果我构建安装程序(travis上的openjdk 10),它就不会(同一台机器).
But the thing that is the strangest is it work when I run it all from intelij (oracle jdk 10) but then if I build the installer(openjdk 10 on travis) it does not (same machine).
它以前也起作用,并且我们没有更改与jna相关的代码或库版本的任何内容. travis使用的openjdk版本可能有所更改,但我看不出它是如何关联的.
Also it worked before and we did not change anything about the code related to jna nor the library version. What might have changed is the openjdk version travis uses, but I can not see how that would be related.
有人知道是什么原因造成的....
Does anybody have an idea what might cause this....
这是失败的实际代码:
Paths.get(Shell32Util.getFolderPath(ShlObj.CSIDL_COMMON_APPDATA), "FAForever")
即使我认为这不是问题……
Even though I thik it is not the problem...
这是jvm日志 https://drive. google.com/file/d/11RpxvFubYM7vCoAE-Kx_6EkIKADPQofE/view?usp=sharing
这可能是重要的部分:
[3.689s][debug][class,resolve ] com.sun.jna.Native java.lang.Object (super)
[3.689s][debug][class,resolve ] com.sun.jna.Native com.sun.jna.Version (interface)
[3.689s][debug][class,resolve ] com.sun.jna.platform.win32.Shell32 com.sun.jna.Native Shell32.java:45 (explicit)
[3.689s][debug][protectiondomain ] Checking package access
[3.689s][debug][protectiondomain ] class loader: a 'jdk/internal/loader/ClassLoaders$AppClassLoader'{0x00000000ee70de08} protection domain: a 'java/security/ProtectionDomain'{0x00000000ef103908} loading: 'com/sun/jna/Native'
[3.689s][debug][protectiondomain ] granted
[3.689s][trace][protectiondomain ] pd set count = #1
[3.689s][debug][class,resolve ] com.sun.jna.platform.win32.Shell32 com.sun.jna.Native Shell32.java:45
[3.689s][info ][stacktrace ] java.lang.NoSuchMethodError, 12
[3.689s][info ][exceptions ] Exception <a 'java/lang/NoSuchMethodError'{0x00000000ef00dd70}: com.sun.jna.Native.load(Ljava/lang/String;Ljava/lang/Class;Ljava/util/Map;)Lcom/sun/jna/Library;> (0x00000000ef00dd70)
thrown [t:/workspace/open/src/hotspot/share/interpreter/linkResolver.cpp, line 741]
for thread 0x00000000031a5000
可能我添加的discord库也包含jna,请参阅jvm的日志:
Probably the discord library I added also contains jna, see log from jvm:
[3.689s][info ][class,load ] com.sun.jna.Native source: file:/E:/DownlordClient%20RC/Downlord's%20FAF%20Client/lib/discord-rpc-1.6.2.jar
推荐答案
与JNA相关的NoSuchMethodError
几乎总是与在依赖列表中某处拥有较旧版本的JNA有关,即使您也具有当前版本.
The NoSuchMethodError
related to JNA is almost always related to having an older version of JNA somewhere in your dependency list, even if you also have the current version.
您在这里的评论给出了提示:
Your comment here gives the hint:
可能我添加的discord库也包含jna,请参阅jvm的日志
Probably the discord library I added also contains jna, see log from jvm
查看该库的POM,我们会看到:
Looking at that library's POM we see:
<name>DiscordRPC</name>
<version>1.6.2</version>
...
<dependencies>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.5.1</version>
<scope>compile</scope>
</dependency>
...
</dependencies>
因此,即使您同时拥有Gradle的依赖项解析,他们也可能选择使用较旧的jna
,并且您可能具有jna-platform
版本5.0.0和jna
版本4.5.1.
So you are likely in a situation where Gradle's dependency resolution has chosen to use the older jna
even though you have both available, and you likely have jna-platform
version 5.0.0 and jna
version 4.5.1.
您应更新构建脚本以强制执行对jna
和jna-platform
使用5.0.0版(或更高版本).
You should update your build script to force use of version 5.0.0 (or more recent) for both jna
and jna-platform
.
这篇关于jna平台中的NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!