Solved Class Not Found Exception On Export

Discussion in 'Plugin Development' started by kmecpp, Sep 1, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    Hi, ive been trying to fix this for the past like 8 hours and have gotten no luck whatsoever. I'm trying to use the Apache NET Commons library but it keeps giving me a class not found exception for the library whenever i export it (When i run the code in Eclipse it works fine) The full error is as follows:

    org.bukkit.command.CommandException: Unhandled exception executing command 'stats' in plugin RubberCubes Analytics v0.1
        at org.bukkit.command.PluginCommand.execute(
        at org.bukkit.command.SimpleCommandMap.dispatch(
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchServerCommand(
        at net.minecraft.server.v1_6_R3.DedicatedServer.t(
        at net.minecraft.server.v1_6_R3.MinecraftServer.s(
    Caused by: java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClient
        at me.kmecpp.util.FTPUtil.upload(
        at me.kmecpp.util.FileUtil.writeStats(
        at org.bukkit.command.PluginCommand.execute(
        ... 8 more
    Currently my project looks like this but ive been screwing around with it for a long time
    and if you need anymore information just ask.

    If anyone can tell me what i'm doing wrong that would be greatly appreciated, Thanks.
  2. Offline


    So, let's take a look.


    So the JVM couldn't find a class.

    Now, if we examine the JAR file itself, with a program like 7-Zip or such, we'll probably notice that the package org.apache.commons doesn't exist.

    So, because of that, you'll need to shade that jar into your plugin, most likely using Maven, or some alternative.
  3. Offline


    zombiekiller753 If it wasn't there then i don't see why it would work flawlessly in the Eclipse IDE?
  4. Offline


    zombiekiller753 Shading libraries is not always a proper solution.
    kmecpp CraftBukkit doesn't know where to find the class files, since it never loaded the jar.
    • Copy the jar in <server root>/lib/<jar name>.jar
    • Add '../lib/<jar name>.jar' to the Class-Path in your manifest file (found in /META-INF/ in the jar)
  5. Offline



    It's imported as a library in Eclipse, but not in your JAR.

    In lolmen's terms, eclipse haz le lib but server no haz.

    Sure.. but requiring libs to be in a folder called 'libs' in the server folder is a better solution?
    Besides, if he were making a plugin, he'd need it to be dynamic. Will he tell everyone "Your server root MUST be here"

    (Also, why doesn't Bukkit just say "Here are all the libs. Go put them in the libs folder"? They shaded too)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 10, 2016
  6. Offline


    It appears that you are not using maven. That means Eclipse won't compile dependencies inside the jar. Get maven, setup a project and add dependencies. Put them to scope: compile, and done.
  7. Offline


    zombiekiller753 When two people shade in the same library, you might have issues referencing classes.
    Hence the relative path.
    Bukkit is software, not a plugin.

    Vilsol that's not the issue here. The issue is that JRE cannot find the classes because they aren't loaded.
  8. Offline


    errrrr..... so who is right?
  9. Offline


    I think you can trust Vilsol if he says it's an issue

    Also, if two people shade the same library, how will there be referencing issues? The classes they reference will be the same

    We're both right. However, personal preference dictates that one of us is more right. We just both think it's ourselves.
  10. Offline


    Vilsol well i decided to go with your way but its kinda confusing... could you plz try and explain it a little better?
  11. Offline


    Personally, I'd go with the maven route as fireblast709 and zombiekiller753 has been saying earlier.

    What you'll need to do is:
    2) Add (what seems to be the Apache Commons net library) to your pom in dependencies, alongside the craftbukkit dependency:
    3) Set up Maven Shade Plugin to relocate ApacheCommons to something like ""
    4) Use Maven's builder with "mvm clean package" and it will build your jar for you :)
    Examples of plugins already doing this:
    Let me know kmecpp if you still have more questions :)
    kmecpp likes this.
  12. Offline


    Try this. When exporting, select "Runnable Jar File". You need to select a Launch configuration but that part doesn't really matter, just select whatever it'll accept. The important part is that you select "Extract required libraries into generated JAR". Press finish and you're done.
  13. Offline


    zombiekiller753 the suggestion Vilsol provided is pretty much the same as adding the jar like he did just now ;3. Shading is a whole new chapter. gabizou provides a decent method with relocation, so use that if you need to shade the classes in ;3
  14. Offline


Thread Status:
Not open for further replies.

Share This Page