Class loading from other jars

Discussion in 'Plugin Development' started by Sgt_Tailor, Jul 23, 2013.

Thread Status:
Not open for further replies.
  1. So I am working on this weapons plugin and making it so that weapons can be added by putting jarfiles in a certain folder but I can't seem to get the classloading to work. This is the code that I have now:

    the loading method

    the Weapons class

    The console showed the following when trying to load a jar with just this class:

    Code:
    17:19:34 [INFO] scanning weapons folder for jar files...
    17:19:34 [INFO] file found
    17:19:34 [INFO] SlammerHammer.jar
    17:19:34 [INFO] SlammerHammer.jar found! Searching for weapons...
    17:19:34 [INFO] [Ljava.net.URL;@aaa3d58
    17:19:34 [INFO] me.sgt_tailor.derp.SlammerHammer
    17:19:34 [SEVERE] Error occurred while enabling Wanted v1.0 (Is it up to date?)
    java.lang.NoClassDefFoundError: Wanted/me/JoTyler/wanted/weapons/Weapon
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(Unknown Source)
            at java.security.SecureClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.access$100(Unknown Source)
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.net.FactoryURLClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at Wanted.me.JoTyler.wanted.Managers.WeaponManager.loadWeaponsFromJar(We
    aponManager.java:77)
            at Wanted.me.JoTyler.wanted.Managers.WeaponManager.loadWeapons(WeaponMan
    ager.java:47)
            at Wanted.me.JoTyler.wanted.Wanted.onEnable(Wanted.java:28)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:457)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:381)
            at org.bukkit.craftbukkit.v1_6_R2.CraftServer.loadPlugin(CraftServer.jav
    a:282)
            at org.bukkit.craftbukkit.v1_6_R2.CraftServer.enablePlugins(CraftServer.
    java:264)
            at net.minecraft.server.v1_6_R2.MinecraftServer.l(MinecraftServer.java:3
    13)
            at net.minecraft.server.v1_6_R2.MinecraftServer.f(MinecraftServer.java:2
    90)
            at net.minecraft.server.v1_6_R2.MinecraftServer.a(MinecraftServer.java:2
    50)
            at net.minecraft.server.v1_6_R2.DedicatedServer.init(DedicatedServer.jav
    a:151)
            at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java
    :391)
            at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:5
    82)
    Caused by: java.lang.ClassNotFoundException: Wanted.me.JoTyler.wanted.weapons.We
    apon
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.net.FactoryURLClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            ... 26 more
     
  2. Offline

    Chiller

    Sgt_Tailor Ive had issues with: if(c.getSuperclass() == Weapon.class){, use this instead:
    if(Weapon.class.isAssignableFrom(c)){

    The superclass of c will return Object unless c implements Weapon and doesnt extend it.
     
  3. Chiller but the problem lies here: Class c = cl.loadClass(className);
     
  4. bump

    md_5 You might be able to help here

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page