当前位置: 首页 > article >正文

IDEA-插件开发踩坑记录-第七坑-Unable to locate JNA native support library

背景

插件里需要要到Neo4j存储一些数据关系。因为插件环境没办法使用用户的Neo4j库,因此需要用到Neo4j的内嵌模式(Embedded)。参考官方文档操作遇到一个问题:

依赖

dependencies{
    // 内置图数据库
    implementation("org.neo4j:neo4j:5.25.1")
}

代码

public static Neo4jService INSTANCE() {
    if (INSTANCE != null) {
        return INSTANCE;
    }
    synchronized (Neo4jService.class) {
        if (INSTANCE != null) {
            return INSTANCE;
        }
        DatabaseManagementService managementService =
                new DatabaseManagementServiceBuilder(Path.of("target/graph.db"))
                        .setConfig(GraphDatabaseSettings.pagecache_memory, ByteUnit.mebiBytes(512))
                        .setConfig(GraphDatabaseSettings.transaction_timeout, Duration.ofSeconds(60))
                        .setConfig(GraphDatabaseSettings.preallocate_logical_logs, true)
                        .build();
        Runtime.getRuntime().addShutdownHook(new Thread(managementService::shutdown));
        INSTANCE = new Neo4jService(managementService.database(GraphDatabaseSettings.DEFAULT_DATABASE_NAME));
        return INSTANCE;
    }
}

异常堆栈 

025-02-28 10:14:39,189 [  31461] SEVERE - #c.i.i.p.PluginManager - Unable to locate JNA native support library
java.lang.UnsatisfiedLinkError: Unable to locate JNA native support library
    at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:1014)
    at com.sun.jna.Native.<clinit>(Native.java:221)
    at org.neo4j.internal.unsafe.UnsafeUtil.allocateMemory(UnsafeUtil.java:276)
    at org.neo4j.io.pagecache.impl.muninn.VictimPageReference.getVictimPage(VictimPageReference.java:38)
    at org.neo4j.io.pagecache.impl.muninn.MuninnPageCache.<init>(MuninnPageCache.java:509)
    at org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory.createPageCache(ConfiguringPageCacheFactory.java:128)
    at org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory.getOrCreatePageCache(ConfiguringPageCacheFactory.java:104)
    at org.neo4j.graphdb.factory.module.GlobalModule.createPageCache(GlobalModule.java:399)

问题分析过程

1、Unable to locate JNA native support library:找不到 JNA 原生支持库

这个就很奇怪,按理来说这个应该是在neo4j里面有依赖的呀?

2、求助idea开发者社区,搜寻答案,找到以为前辈的踩坑分享:

Carol Navarro Pereira

创建于 2024年10月10日 18:36

评论操作

At the end we were able to find the problem, it was the library

jnidispatch.dll

It is into the webstorm application and also inside the jna library so there is a problem trying to load the library twice. Removing the library for the webstorm version fixed the problem.

3、从上面的分享可以看出,他里面分享了一条关键信息,jnidispatch.dll 这个被内置到idea里了;

4、查idea的文件夹,发现文件 \lib\jna\amd64\jnidispatch.dll

5、有了jna的dll文件,那么就没必要自己加jna的包了,所以在依赖里排除jna;

dependencies{
    // 内置图数据库
    implementation("org.neo4j:neo4j:5.25.1"){
        exclude(group = "net.java.dev.jna", module = "jna")
    }
}

6、重启调试,一切恢复正常; 

结论

这个问题是由于jnidispatch.dll 这个被内置到idea里了,而Neo4j依赖里包含了jna,导致jna被加载了两次。因此需要排除一个地方的jna,作为插件开发者,当然是移除依赖包的jna啦。


http://www.kler.cn/a/566783.html

相关文章:

  • 第15届 蓝桥杯 C++编程青少组中/高级选拔赛 202403 真题答案及解析
  • threeJs+vue 加载gltf模型、获取模型尺寸、播放模型动画
  • React vs Vue3深度对比与使用场景分析
  • 使用机器学习进行土地覆盖分类
  • 网络安全和爬虫的关系
  • elementUI 表格隔行换色,修改table表头背景样式
  • 排序算法归类整理对比
  • 002-快速安装 Linux 虚拟机
  • PyCharm中通过命令行执行`pip`命令下载到哪里了:虚拟环境目录下
  • 如何通过网管提升运维效率?
  • 游戏引擎学习第125天
  • Shell学习(5/6) 流程控制-函数
  • 数据结构秘籍(二)图(含图的概念、存储以及图的两大搜索)
  • 无人机定点运输技术!
  • CSS 系列之:grid 布局
  • Windows环境下安装Redis并设置Redis开机自启
  • React进阶之前端业务Hooks库(三)
  • docker部署go简单web项目(无mysql等附加功能)
  • React组件化深度解析(二):从受控组件到生命周期现代化
  • 【Wireshark 02】抓包过滤方法