简体   繁体   English

jna平台中的NoSuchMethodError

[英]NoSuchMethodError in jna-platform

I wanna make a new release of the application but when starting it it throws NoSuchMethodError 我想发布该应用程序的新版本,但启动时会引发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)

Similar to NoSuchMethodError using JNA User32 platform map However I do have version 5.0.0 of both libaries. 类似于使用JNA User32平台图的NoSuchMethodError。但是我确实有两个库的版本5.0.0。

It is about this project https://github.com/FAForever/downlords-faf-client it uses gradle as a build tool... 关于这个项目https://github.com/FAForever/downlords-faf-client它使用gradle作为构建工具...

Also I decompiled the installed program and found the method that java claims is not present in the jna libary. 另外,我反编译了已安装的程序,并发现jna库中没有java声明的方法。 Which I find super weird. 我觉得这很奇怪。

Also I check no other dependency has a dependency on jna. 我也检查没有其他依赖项对jna有依赖性。

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). 但是,最奇怪的是,当我从intelij(oracle jdk 10)运行所有程序时,它可以工作,但是如果我构建安装程序(travis上的openjdk 10),则不会(同一台机器)。

Also it worked before and we did not change anything about the code related to jna nor the library version. 之前它也起作用,并且我们没有更改与jna相关的代码或库版本的任何内容。 What might have changed is the openjdk version travis uses, but I can not see how that would be related. travis使用的openjdk版本可能有所更改,但是我看不到它是如何关联的。

Does anybody have an idea what might cause this.... 是否有人知道可能会导致这种情况的...。

This is the actual code that fails: 这是失败的实际代码:

Paths.get(Shell32Util.getFolderPath(ShlObj.CSIDL_COMMON_APPDATA), "FAForever")

Even though I thik it is not the problem... 即使我想这也不是问题...

This is the jvm log https://drive.google.com/file/d/11RpxvFubYM7vCoAE-Kx_6EkIKADPQofE/view?usp=sharing 这是jvm日志https://drive.google.com/file/d/11RpxvFubYM7vCoAE-Kx_6EkIKADPQofE/view?usp=sharing

Of which this is probably the important part : 其中可能是重要的部分:

[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

Probably the discord library I added also contains jna, see log from jvm: 我添加的discord库可能还包含jna,请参阅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

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. 与JNA相关的NoSuchMethodError几乎总是与在您的依赖项列表中某处拥有较旧版本的JNA有关,即使您也具有当前版本。

Your comment here gives the hint: 您在这里的评论给出了提示:

Probably the discord library I added also contains jna, see log from jvm 我添加的discord库可能也包含jna,请参阅jvm的日志

Looking at that library's POM we see: 查看该库的POM,我们看到:

<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>

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和jna 4.5.1版。

You should update your build script to force use of version 5.0.0 (or more recent) for both jna and jna-platform . 您应该更新构建脚本,以强制jnajna-platform使用版本5.0.0(或更新的版本)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM