gpt4 book ai didi

java - apache在创建JedisConfig对象时在运行时公共(public)ClassNotFoundException

转载 作者:可可西里 更新时间:2023-11-01 11:23:14 24 4
gpt4 key购买 nike

我正在为minecraft spigot 1.14.2构建一个插件,它可以访问redis缓存。我正在使用绝地武士客户端访问缓存。
每当我试图创建JedisPool时,都会发生以下错误:

[00:26:09] [Server thread/ERROR]: Could not load 'plugins/test.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:139) ~[spigot-1.14.4.jar:git-Spigot-798ea6a-b2bcde8]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:334) ~[spigot-1.14.4.jar:git-Spigot-798ea6a-b2bcde8]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:253) [spigot-1.14.4.jar:git-Spigot-798ea6a-b2bcde8]
at org.bukkit.craftbukkit.v1_14_R1.CraftServer.loadPlugins(CraftServer.java:350) [spigot-1.14.4.jar:git-Spigot-798ea6a-b2bcde8]
at net.minecraft.server.v1_14_R1.DedicatedServer.init(DedicatedServer.java:202) [spigot-1.14.4.jar:git-Spigot-798ea6a-b2bcde8]
at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:775) [spigot-1.14.4.jar:git-Spigot-798ea6a-b2bcde8]
at java.lang.Thread.run(Thread.java:834) [?:?]
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
at java.lang.Class.forName0(Native Method) ~[?:?]
at java.lang.Class.forName(Class.java:398) ~[?:?]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:59) ~[spigot-1.14.4.jar:git-Spigot-798ea6a-b2bcde8]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot-1.14.4.jar:git-Spigot-798ea6a-b2bcde8]
... 6 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool2.impl.GenericObjectPoolConfig
at java.net.URLClassLoader.findClass(URLClassLoader.java:471) ~[?:?]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:135) ~[spigot-1.14.4.jar:git-Spigot-798ea6a-b2bcde8]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:81) ~[spigot-1.14.4.jar:git-Spigot-798ea6a-b2bcde8]
at java.lang.ClassLoader.loadClass(ClassLoader.java:588) ~[?:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[?:?]
at java.lang.Class.forName0(Native Method) ~[?:?]
at java.lang.Class.forName(Class.java:398) ~[?:?]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:59) ~[spigot-1.14.4.jar:git-Spigot-798ea6a-b2bcde8]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot-1.14.4.jar:git-Spigot-798ea6a-b2bcde8]
... 6 more

我的 Test.java
package pkg;

import redis.clients.jedis.*;

import org.bukkit.plugin.java.JavaPlugin;

public class Test extends JavaPlugin{

@Override
public void onEnable(){
JedisPool cachePool = new JedisPool(new JedisPoolConfig(), "127.0.0.1", 6379);
try (Jedis j = cachePool.getResource() ) {
j.set("foo", "bar");
}
cachePool.close();
}

@Override
public void onDisable(){}
}

因为这看起来像一个依赖性问题,我还将在这里包括我的 build.gradle
apply plugin:'java'

sourceCompatibility = '1.11'
targetCompatibility = '1.11'

repositories {
mavenCentral()

maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}

maven {
url "https://hub.spigotmc.org/nexus/content/repositories/snapshots"
}
}

dependencies {
compile "redis.clients:jedis:3.1.0"
compile "org.spigotmc:spigot-api:1.14.2-R0.1-SNAPSHOT"
}

processResources {
from "src/plugin.yml"
}

这发生在新安装的插口服务器上。此外,这个问题仅限于在插件中创建 JedisPool的实例。我可以编写一个外部项目,这个项目没有spiget作为依赖项,创建一个 JedisPool很好。是什么导致了这个问题?如果还有什么我可以提供的信息,请告诉我。

最佳答案

在依赖项中添加Apache Commons Pool
例如。

dependencies {
compile "redis.clients:jedis:3.1.0"
compile "org.apache.commons:commons-pool2:2.6.2"
compile "org.spigotmc:spigot-api:1.14.2-R0.1-SNAPSHOT"
}

关于java - apache在创建JedisConfig对象时在运行时公共(public)ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57651886/

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