Solved java.lang.NoClassDefFoundError on plugin enable

Discussion in 'Plugin Development' started by stirante, Jan 19, 2013.

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

    stirante

    Hi!
    I have error when enabling my plugin:
    Code:
    2013-01-19 17:08:19 [SEVERE] Could not load 'plugins/ChunkWars_Items.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: com/stirante/ChunkWars/Mod/KeyListener
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:184)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.v1_4_6.CraftServer.loadPlugins(CraftServer.java:239)
        at org.bukkit.craftbukkit.v1_4_6.CraftServer.<init>(CraftServer.java:217)
        at net.minecraft.server.v1_4_6.PlayerList.<init>(PlayerList.java:52)
        at net.minecraft.server.v1_4_6.DedicatedPlayerList.<init>(SourceFile:11)
        at net.minecraft.server.v1_4_6.DedicatedServer.init(DedicatedServer.java:104)
        at net.minecraft.server.v1_4_6.MinecraftServer.run(MinecraftServer.java:399)
        at net.minecraft.server.v1_4_6.ThreadServerApplication.run(SourceFile:849)
    Caused by: java.lang.NoClassDefFoundError: com/stirante/ChunkWars/Mod/KeyListener
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173)
        ... 9 more
    Caused by: java.lang.ClassNotFoundException: com.stirante.ChunkWars.Mod.KeyListener
        at java.net.URLClassLoader$1.run(URLClassLoader.java:299)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:288)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:287)
        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:425)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        ... 12 more
    
    I have 2 plugins. ChunkWars_Items and ChunkWars_Mod. In Items plugin i create simple interface from Mod:
    Code:
            KeyboardManager.registerListener(new KeyListener() {
                @Override
                public void onKeyPressed(int keyCode, Player player) {
                    Bukkit.broadcastMessage(player.getName() + " pressed " + keyCode);
                }
            });
    Interface:
    Code:
    package com.stirante.ChunkWars.Mod;
    
    import org.bukkit.entity.Player;
    
    public interface KeyListener {
        public void onKeyPressed(int keyCode, Player player);
    }
    Both plugins are on server.
    Can anyone help?
     
  2. Offline

    Phinary

    The path you put into the plugin.yml needs to go to a class that extends JavaPlugin. It looks to me like you aren't even using Bukkit API. For Bukkit plugins you have to use the bukkit api...

    main should be: path.to.class.ClassName

    You can reference this for more help: http://wiki.bukkit.org/Plugin_YAML

    As well as this for how to use Bukkit's API: http://wiki.bukkit.org/Plugin_Tutorial
     
  3. Offline

    stirante

    I use Bukkit API. Second plugin is called Mod becouse it's API for mod.
     
  4. Offline

    t7seven7t

    stirante If your second plugin doesn't have a main class and plugin.yml also then you will need to write your own class loader to load the classes into memory for Java to execute them. For simplicity it would be best just to make it another plugin.
     
  5. Offline

    Phinary

    Nevermind, read that wrong..

    Anyways, check the edit on my post above.
     
  6. Offline

    stirante

    Both are extending JavaPlugin. Btw using static methods from other plugin don't throw any errors.

    KeyboardManager is my class. It handles informations from CustomPayload from Mod in client.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  7. Offline

    Phinary

    Yeah, that is why I read that wrong. Anyways, as stated you either need to load it as a plugin with a class that extends javaplugin or figure out a way to load it yourself.
     
  8. Offline

    stirante

    But why static methods from second plugin are working great and creating Interface from second plugin don't work?
     
  9. Offline

    Sagacious_Zed Bukkit Docs

    the main attribute should be the fully qualified name fo your class.
     
  10. Offline

    Phinary

    Because the second plugin isn't actually loaded, so you cant access it as a library? I may be wrong though

    Bleh, I have no idea. My best guess would be try to get your second plugin running as an actual plugin or just use the second plugin classes in your first plugin.
     
  11. Offline

    Sagacious_Zed Bukkit Docs

    If plugin A requires Plugin B, Plugin A better declare that it needs Plugin B in it's plugin.yml
     
    stirante likes this.
  12. Offline

    stirante

    How?

    EDIT:Nvm, Thanks :D

    EDIT2:It works! Thanks to all of you :D
     
Thread Status:
Not open for further replies.

Share This Page