Debugging Plugins in Eclipse

Discussion in 'Resources' started by GDorn, Feb 11, 2011.

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


    If you've never used a debugger before, you may find this quite helpful. It's tricky to set up eclipse's debugger to run a jar file, though, and craftbukkit's dynamic plugin loading can compound the problem. I just got it working, so here's what I did.

    You'll need the craftbukkit jar file and the minescraft server jar file. You'll be running a server locally.

    Set up your paths like this (I'll use $PROJECT to refer to the base of your project):
    craftbukkit.jar and minecraft_server.jar go in $PROJECT/dist
    MyPlugin.jar goes in $PROJECT/dist/plugins (so that craftbukkit will see it).
    Any configuration goes in $PROJECT/dist/plugins/MyPlugin

    In eclipse, do this:
    1. Open Run, Run Configurations and then create a new Java Application configuration.
      1. In the Classpath tab, remove everything from 'User Entries'. In 'Bootstrap Entries' ensure that the JRE library is shown. Also add two external JARs - the craftbukkit.jar and the minecraft_server.jar.
      2. In the Main tab, set the Main class to 'org.bukkit.craftbukkit.Main'.
      3. In the Arguments tab, set the working directory to $PROJECT/dist (the path where the craftbukkit.jar lives). If you forget to do this step, craftbukkit.jar will be invoked from the project's root and it won't find your plugin.
    2. Save all of this and then test it using Run. This should start a minecraft server and the output should show up in the Console window.
    3. To debug something, add a breakpoint in your code somewhere. A good place to start is the onEnable() method. You will then need to recreate MyPlugin.jar. If you find yourself doing this repeatedly, consider creating a .jardesc file to speed up the process.
    4. Then run the debugger (Run, Debug). The server will start and run your plugin until it gets to the breakpoint. Of course, if your breakpoint can only be reached via an event, you'll need to trigger that event which probably means logging into the server.
    5. Now that you are at the breakpoint, eclipse will be showing you the debugger perspective. I won't go into too much detail here about how to use the debugger, but most likely the most interesting thing is the Variables browser, which will let you inspect the variables in scope at the breakpoint.
    6. When you are done, you can stop your server either manually or via the red square stop button at the top of the Console pane.
    Hope somebody finds this helpful.
  2. You, sir, are a gentleman and a scholar. I've been having a hard time adjusting to traditional debugging techniques lately. God, I think I might have spoiled myself with fancy IDEs :( It's not that I can't debug without the debugger, I just feel like I'm working so much slower by just doing print statements and the like.

    But anyway, thanks for the help :) I couldn't get it to work correctly at first with the runnable jar
  3. Offline


    This is very awesome, but should likely be moved to the "Resources" sub-forum. Either way, you get a 'like' from me!
  4. Offline


    This is awesome, you so rock. +1,000
  5. Offline


    The eclipse console didn't work for me in windows, adding
    to the vm args fixes this, but after each executing a command bukkit will nag you with "unknown console command"
  6. Offline


    Where do I get minecraft_server.jar? Is this the plain vanilla server or do I need to somehow build mc-dev? When I try to Run, eclipse tells me it can't find "net.minecraft.server.Main", and I'm not sure what I did wrong...

    EDIT: I got it to load by adding craftbukkit-0.0.1-SNAPSHOT.jar from the CraftBukkit project instead of using Add External JARs... which seems to convert my full path to an incorrectly defined relative path when I save the run configuration. Ideas?

    EDIT (again): Now it seems to be working, set up just as you described; the server wasn't binding to a port (production is running on the same machine) and if it can't bind a port it's apparently a big mess for everything; seems fine now. Thanks a million this makes developing so much easier!
  7. Offline


    I took the minecraft_server.jar out of the craftbukkit.jar and copied the contents of craftbukkit.jar/net/minecraft/server into it. I tried to compile mc-dev too, but it had 500 missing IOExceptions...I wonder how they compile it?
    Was it just one master try{}catch{} missing which would catch all?
    I think Dinnerbone fixed the issue with the unknown command by removing the ">" in UnsupportedTerminal mode, but I didn't try it.
  8. Offline


    I've had no issues with it once it was working. If you've seen some of my other posts, I've had a HELL of a time getting eclipse set up and working properly but it seems to be in order now. I'm actually using the github craftbukkit with a symlink to the /target folder of the project so I can pull anytime there is a new build (optional of course) and the vanilla minecraft_server.jar.

    The only caveat with this method is that breakpoints will time-out the client when you hit them (server stops responding because it's paused), but you can step through the code just fine as if the client was still connected until it gets back around to checking sockets, so it's not so bad. There was another thread about using Beanshell for live debugging and yet another on setting up a test environment to use against multiple RBs; perhaps when I finish up my plugin I should start putting together a tutorial on the Wiki about setting up all three (although I haven't tried either of these yet)
  9. Offline


    I'd also just like to add that on the Run Configuration's "Arguments" tab, adding "-nojline" to the Program Arguments makes the Eclipse console so much easier to read and work with.
  10. Offline


    Lol looks complicated, I just have a test server that I dont give anyone the IP to ... lol :p
  11. Offline


    Yeah, that is easier in some ways (especially now that you can just build into the cb/plugins/update folder and then /reload the server without even stopping it), but you can't step through your code or watch/change variables in realtime.
  12. I am getting this error when trying to run the debug server in eclipse.
    On my real server the plugin just works fine.

    21:14:22 [SCHWERWIEGEND] Could not load 'plugins\LevelUP.jar' in folder 'plugins':
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(
        at net.minecraft.server.MinecraftServer.e(
        at net.minecraft.server.MinecraftServer.a(
        at net.minecraft.server.MinecraftServer.init(
    Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: Error constructing com.avaje.ebeaninternal.server.core.DefaultServerFactory
        at com.avaje.ebean.EbeanServerFactory.createServerFactory(
        at com.avaje.ebean.EbeanServerFactory.<clinit>(
        ... 10 more
    Caused by: java.lang.IllegalArgumentException: Error constructing com.avaje.ebeaninternal.server.core.DefaultServerFactory
        at com.avaje.ebeaninternal.api.ClassUtil.newInstance(
        at com.avaje.ebeaninternal.api.ClassUtil.newInstance(
        at com.avaje.ebean.EbeanServerFactory.createServerFactory(
        ... 11 more
    Caused by: java.lang.NullPointerException
        at com.avaje.ebeaninternal.api.ClassLoadContext.getDefault(
        at com.avaje.ebeaninternal.api.ClassLoadContext.forName(
        at com.avaje.ebeaninternal.api.ClassUtil.forName(
        at com.avaje.ebeaninternal.api.ClassUtil.newInstance(
        ... 13 more
  13. Offline


    Not sure if it was said but you need to add all jars from the craftbukkit jar to the bootstrap, but I don't know whether thats the problem
  14. Where do I find the bootstrap config?
    And where are the Jars in the craftbukkit.jar? I only have folders in there.
  15. Offline


  16. Offline


    You can also debug directly at your server with the java remote debugger. To do this you just have to add the following otion to the start command of your server:
    you can adjust the port to whatever port you want. The suspend option tells weather the program should continue when there is no debugger connected.
    To dubug in Eclipse go to the debug configurations and add a new Remote Java Application. Enter the address of your server and the port, then click on debug and have fun!
    BobbyD441, desht and 4am like this.
  17. Offline


    Yeah but can you change the code while debugging?
  18. Offline


    I can not start the debug process, eclipse output:

    01:20:18 [INFO] Starting minecraft server version 1.0.0
    01:20:18 [WARNUNG] **** NOT ENOUGH RAM!
    01:20:18 [WARNUNG] To start the server with more ram, launch it as "java -Xmx1024M -Xms1024M -jar minecraft_server.jar"
    01:20:18 [INFO] Loading properties
    01:20:18 [INFO] Starting Minecraft server on *:25565
    01:20:18 [SCHWERWIEGEND] java.lang.NullPointerException
    01:20:18 [SCHWERWIEGEND]     at org.bukkit.craftbukkit.util.Versioning.getBukkitVersion(
    01:20:18 [SCHWERWIEGEND]     at org.bukkit.craftbukkit.CraftServer.<init>(
    01:20:18 [SCHWERWIEGEND]     at net.minecraft.server.ServerConfigurationManager.<init>(
    01:20:18 [SCHWERWIEGEND]     at net.minecraft.server.MinecraftServer.init(
    01:20:18 [SCHWERWIEGEND]     at
    01:20:18 [SCHWERWIEGEND]     at
    01:20:18 [SCHWERWIEGEND] Unexpected exception
        at org.bukkit.craftbukkit.util.Versioning.getBukkitVersion(
        at org.bukkit.craftbukkit.CraftServer.<init>(
        at net.minecraft.server.ServerConfigurationManager.<init>(
        at net.minecraft.server.MinecraftServer.init(
    But Bukkit does work from the windows console problems.
  19. Offline


    Great tutorial, works nicely for me
  20. Offline


    I am having the exact same issue as lordfritte. Anyone know of a fix?
  21. Offline


    CubieX and kumpelblase2 like this.
  22. The way I fixed that NullPointer was instead of putting the craftbukkit.jar and minecraft_server.jar in the Bootstrap Entities, I put them in the User Entities. Don't know if this will help anyone, but it works for me :)
    wiedzmin137 likes this.
  23. That does the trick! BTW: No need for any other jars than the craftbukkit one. :)

    //EDIT: Hum, but what's so special about it? It doesn't auto-include the plugin (I still have to compile it, pack it and move it to the plugins folder). I wanted to play with exploding arrows like Notch... :'(
  24. Offline


    Anyone know how to do this in NetBeans? And before you hate on me for using NetBeans, it's cause Eclipse won't work for me, it always freezes :p
  25. Offline

    gus's saying that the jars i referenced don't exist. they're still there, though.
  26. Offline


    Close the projects and restart eclipse; make sure you have write privs on the eclipse directory and everything beneath it - Eclipse can act silly in such conditions without really telling you what is wrong...
  27. Offline


    I'm getting this error: "java.lang.NoSuchMethodError: net.minecraft.server.MinecraftServer.main(Ljoptsimple/OptionSet;)V
    at org.bukkit.craftbukkit.Main.main(" whenever I try to run it. Any ideas what could be wrong?
  28. Eclipse could not find the jar files, Just needed to Refresh The Project files :)

    (Added files in Explorer.)

    This Worked.

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


    I got this when I tried to run it.
    12:40:14 [SEVERE] java.lang.NullPointerException
    >12:40:14 [SEVERE]    at org.bukkit.craftbukkit.v1_6_R3.util.Versioning.getBukkitVersion(
    >12:40:14 [SEVERE]    at org.bukkit.craftbukkit.v1_6_R3.CraftServer.<init>(
    >12:40:14 [SEVERE]    at net.minecraft.server.v1_6_R3.PlayerList.<init>(
    >12:40:14 [SEVERE]    at net.minecraft.server.v1_6_R3.DedicatedPlayerList.<init>(SourceFile:11)
    >12:40:14 [SEVERE]    at net.minecraft.server.v1_6_R3.DedicatedServer.init(
    >12:40:14 [SEVERE]    at
    >12:40:14 [SEVERE]    at
    >12:40:14 [SEVERE] Encountered an unexpected exception NullPointerException
        at org.bukkit.craftbukkit.v1_6_R3.util.Versioning.getBukkitVersion(
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.<init>(
        at net.minecraft.server.v1_6_R3.PlayerList.<init>(
        at net.minecraft.server.v1_6_R3.DedicatedPlayerList.<init>(SourceFile:11)
        at net.minecraft.server.v1_6_R3.DedicatedServer.init(
    >12:40:14 [SEVERE] This crash report has been saved to: /Users/videogames/Documents/workspace/MC_Server/./crash-reports/crash-2013-09-21_12.40.14-server.txt
  30. Offline


    Thumbs up. Very useful :D
Thread Status:
Not open for further replies.

Share This Page