簡體   English   中英

我編譯后,一個罐子拋出ClassNotFoundException

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

我的project / 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進行開發和編譯。 解決此問題的一再建議是將項目導出為可運行的Jar文件。 但是,這是一個插件,因此沒有“ main”方法。

還有其他想法嗎? 我覺得我已經筋疲力盡了(...我自己和)在google和stackoverflow上找到的所有選項。

謝謝!

只是考慮罐子的傳遞依賴關系。 您是否認為其中一個罐子中包含以下類JSONReader。 通常使用Jackson或任何此類框架,我遇到了jar的傳遞依賴項,jackson jar依賴於其他jar。 通常,在編譯時不需要這些可傳遞依賴項,但是在運行時則需要,因此我們最終會遇到NoClassDefFound錯誤。

如果是這種情況,我建議使用maven避免所有此類依賴項的麻煩。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM