我的项目/lib 文件夹中有 9 个 jar 文件,我的类路径似乎是准确的。在我编译之前一切正常,但是在编译一个 jar stringtree-json-2.0.5.jar 之后,当我尝试运行它时会抛出 ClassNotFoundException。
我尝试过的事情:
- 使用“*”一次加载我的 lib 文件夹中的所有内容
- 从使用 Jackson 切换(假设它是特定于 jar 的),但 Stringtree 有完全相同的问题。有问题的 jar 只是一个我只使用一次的 json 解析器(在关键区域)。
- 尝试在编译之前和之后更改类路径以确保它是正确的。
- 可能还有很多我不记得了……被困在这个问题上一个星期左右。
这是抛出的错误:
org.bukkit.command.CommandException: Unhandled exception executing command 'rate' in plugin Pariah v1
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:189)
at org.bukkit.craftbukkit.v1_5_R2.CraftServer.dispatchCommand(CraftServer.java:523)
at net.minecraft.server.v1_5_R2.PlayerConnection.handleCommand(PlayerConnection.java:966)
at net.minecraft.server.v1_5_R2.PlayerConnection.chat(PlayerConnection.java:884)
at net.minecraft.server.v1_5_R2.PlayerConnection.a(PlayerConnection.java:841)
at net.minecraft.server.v1_5_R2.Packet3Chat.handle(Packet3Chat.java:44)
at net.minecraft.server.v1_5_R2.NetworkManager.b(NetworkManager.java:292)
at net.minecraft.server.v1_5_R2.PlayerConnection.d(PlayerConnection.java:110)
at net.minecraft.server.v1_5_R2.ServerConnection.b(SourceFile:35)
at net.minecraft.server.v1_5_R2.DedicatedServerConnection.b(SourceFile:30)
at net.minecraft.server.v1_5_R2.MinecraftServer.r(MinecraftServer.java:580)
at net.minecraft.server.v1_5_R2.DedicatedServer.r(DedicatedServer.java:225)
at net.minecraft.server.v1_5_R2.MinecraftServer.q(MinecraftServer.java:476)
at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java:409)
at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:573)
Caused by: java.lang.NoClassDefFoundError: org/stringtree/json/JSONReader
at pariah.AllMethods.ratingCall(AllMethods.java:351)
at pariah.AllMethods.getPathRankRating(AllMethods.java:308)
at pariah.Pariah.onCommand(Pariah.java:63)
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
... 15 more
Caused by: java.lang.ClassNotFoundException: org.stringtree.json.JSONReader
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:80)
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 19 more
这是我当前的类路径:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="test">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="lib/commons-codec-1.6.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-logging-1.1.1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/httpclient-4.2.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/httpclient-cache-4.2.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/httpcore-4.2.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/httpmime-4.2.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/stringtree-json-2.0.5.jar"/>
<classpathentry exported="true" kind="lib" path="lib/bukkit-1.5.1-R0.1-20130325.184829-14.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
我正在使用eclipse进行开发和编译。解决此问题的一个经常重复的建议是将项目导出为 Runnable Jar 文件。但是,这是一个插件,因此没有“主要”方法。
还有其他想法吗?我觉得我已经用尽了(......我自己和)我在 google 和 stackoverflow 上找到的所有选项。
谢谢!