2013-05-03 73 views
0

我有9个jar文件在我的项目/ lib文件夹和我的类路径似乎是准确的。在我编译之前,一切正常,但是在编译单个jar之后,stringtree-json-2.0.5.jar在我尝试运行它时抛出ClassNotFoundException异常。单个jar抛出ClassNotFoundException后我编译

事情我已经尝试:

  • Using '*' to load everything in my lib folder at once
  • 使用杰克逊交换(假设它是罐子具体),但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 

这是我目前的classpath:

<?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来开发和编译。解决此问题的重复建议之一是将项目导出为可运行Jar文件。但是,这是一个插件,因此没有“主要”方法。

有没有其他想法呢?我觉得我已经筋疲力尽(...我自己和)我在google和stackoverflow上找到的所有选项。

谢谢!

回答

0

只是考虑jar的传递依赖关系。你认为你在其中一个罐子里有下面的JSONReader类吗?通常使用杰克逊或任何这样的框架,我遇到了罐子的传递依赖,杰克逊罐子依赖于其他罐子。通常在编译时这些传递依赖不是必需的,但是在运行时他们是,我们最终面临着NoClassDefFound错误。

如果是这样的话,我会建议使用maven来避免所有这些依赖关系的麻烦。

相关问题