简体   繁体   English

我编译后,一个罐子抛出ClassNotFoundException

[英]A single jar throws ClassNotFoundException AFTER I have compiled

I have 9 jar files in my project/lib folder and my classpath appears to be accurate. 我的project / lib文件夹中有9个jar文件,并且我的类路径似乎正确。 Everything works fine before I compile, but after compiling a single jar, stringtree-json-2.0.5.jar, throws ClassNotFoundException when I try to run it. 在编译之前,一切正常,但在编译单个jar时,stringtree-json-2.0.5.jar在我尝试运行它时抛出ClassNotFoundException。

Things I've tried: 我尝试过的事情:

  • Using '*' to load everything in my lib folder at once 使用“ *”一次将所有内容加载到我的lib文件夹中
  • Switched from using Jackson (assuming it was jar specific), but Stringtree has the exact same problem. 从使用Jackson切换到(假设它是jar特定的),但是Stringtree存在完全相同的问题。 The offending jar is just a json parser that I just use once (in a pivotal area). 令人讨厌的jar只是我只使用过一次(在关键区域)的json解析器。
  • Tried altering classpath before and after compile to insure it's correct. 尝试在编译前后更改类路径,以确保其正确。
  • Probably a lot more I don't remember... been stuck on this for a week or so. 可能还有很多我不记得了……被坚持了一周左右。

Here's the error as it's thrown: 这是抛出的错误:

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

This is my current 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>

I'm using eclipse to develop and compile. 我正在使用Eclipse进行开发和编译。 One oft repeated suggestion for solving this is to export the project as a Runnable Jar File. 解决此问题的一再建议是将项目导出为可运行的Jar文件。 However, this is a plugin and so has no 'main' method. 但是,这是一个插件,因此没有“ main”方法。

Any other ideas out there? 还有其他想法吗? I feel I've exhausted (...myself and) all the options I've found on google and stackoverflow. 我觉得我已经筋疲力尽了(...我自己和)在google和stackoverflow上找到的所有选项。

Thanks! 谢谢!

Just thinking around the transitive dependencies of the jar. 只是考虑罐子的传递依赖关系。 Do you think you have the following class JSONReader in one of the jars. 您是否认为其中一个罐子中包含以下类JSONReader。 Generally using Jackson or any such frameworks, I have come across the transitive dependency of jars, jackson jar is dependent on other jars. 通常使用Jackson或任何此类框架,我遇到了jar的传递依赖项,jackson jar依赖于其他jar。 Generally at compile time those transitive dependencies are not required but at the run time they are and we end facing NoClassDefFound error. 通常,在编译时不需要这些可传递依赖项,但是在运行时则需要,因此我们最终会遇到NoClassDefFound错误。

If that is the case, I would suggest to use maven for avoiding all such dependencies hassles. 如果是这种情况,我建议使用maven避免所有此类依赖项的麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM