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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值