First of all, I am not native English speaker so try to take my grammar lightly

1. Intro
Every developer sooner or later need test his code more deeply and require info about object state and variable values. Most of you would probably use System.out.print() method to print desired data to console, then restart server or reload script. Its archaic solution without any flexibility. In this tutorial I will show you how to use modern java debugging techniques, mostly from eclipse.
2. Basic debugging in eclipse
Eclipse contains one of the best debugger I ever saw, not mention only java IDEs. Debugging simple application in eclipse is for two mouse clicks. You take java file with main() method, right click on file and in menu select Debug As -> Java Application. Eclipse will start program in debug mode.
In Debug view you can see active threads of your application. You can pause them and resume again anytime. While thread is paused you can inspect variables values and use steps. Steps allow you to continue executing paused thread but all is now under your control. Basic steps in code are step into, over and return. First, Step Into, will always follow inside calling method. Second, Step Over, will executed one line of code. Last, Step Return, will move debug cursor back to line from which actual method was called from. I recommend to test this on some small application.
Ok, pausing threads is cool but how to pause thread in my code? Answer is breakpoints - section 4.
So hurray we know how to debug, lets debug l2j gameserver! Wrong.. L2J is much more complex piece of software and require datapack, configs, libs, etc. Best way to start GS in debug mode is use launcher - section 3.
3. Launchers
Launcher is simple XML file which eclipse can parse and start program with additional parameters and configurations. L2J GS already contains pre-made launchers almost ready to use. Since I think none of l2j developers use them, I take over and put there mine own configurations. So open L2 GameServer.launch as normal text file and search for line:
Code: Select all
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="D:/_l2j/gameserver/"/>
Now if you did everything right, you should see in console loading GS.
4. Breakpoints
Now since you are in debug mode you can start adding breakpoints to your code wherever you want start debugging. Just find a desired lines of code and on free space on left make double click. If you did it right, small blue dot should appear. Now if any application thread reach this breakpoint, debugger pause thread and you can start using steps and check variables values.
This is nice but L2J is multithreaded and more threads can pause on my breakpoints and cause server lag. To prevent this you can use Conditional breakpoint. It means thread will pause only if condition is met. Right click on breakpoint - breakpoint properties. Check condition and you can write code. It can be for example:
Code: Select all
this.getNpc().getNpcId() == 16064
More info about debugging can be found at http://www.vogella.de/articles/EclipseD ... ticle.html (they have some nice pictures

Next part is much more interesting and for sure will save you some time.
5. Hot code replace
While JVM running application in debugging mode it allows you transfer through debugging channel new class files. HUH?!?? YES, it means you can modify core java files and changes will directly apply to running GameServer. No more restarting GS if you made small typo, big mistake or just forget call method. This apply to DataPack java scripts as well. Everything which sound perfect must have some catch


More info: http://wiki.eclipse.org/FAQ_What_is_hot_code_replace%3F
6. Java Profilers
<TODO>
This is the end and I am sure I forgot mention something. I hope you like it and hopefully it will help you with l2j gs debugging.