Quick explanation what this is: Remote Debugging empowers you to stop the program at specific points to e.g. check the value of variables and quickly adjust them. It also makes it possible to change code without reloading / restarting the server. Not everything can be changed this way though.
Thought I'd make a tutorial on how to remote debug using IntelliJ since there are no detailed, recent examples or tutorials. In this tutorial I will be using IntelliJ IDEA 15, however the process should be similar for other versions of the IDE. Please note this tutorial will work with both Windows and macOS.
Project to Test/Use With
< 3 Minutes
Step 1 | Setting Up IntelliJ
- Navigate to Run > Edit Configurations
- You should now see the window below, click + (top left) > Remote
- You have created a new configuration! Now we need to set it up. Give it a name, set the port (I've used 5005) and copy the text from the top text box (you can see I have highlighted it below) we will be using it to set up the server. Hit Apply > OK to save and close this window.
* Make sure "Search sources using module's classpath" is set to your project or it will not work!*
Step 2 | Editing the Server Startup Command
- Now we need to add the arguments to the startup script. Open the start_server.command or start_server.bat and paste the following arguments before the '-jar spigot.jar' on the same line. We have just copied these from the Edit Configurations window in the previous step.
- This is how mine looked after the addition, yours should look similar.
java -Xmx2G -Xms2G -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar ./spigot.jar
- Save the file and start your server. When it has loaded up fully move onto the next step.
Step 3 | Connecting IntelliJ and Compiling
- Take a look in the top right-hand corner of IntelliJ and you should see the name of the new configuration you have just made, and a few buttons like as pictured.
(NB. If your config isn't selected, please select it from the dropdown)
- Hit the green Bug button to connect, the following console will popup in the bottom corner of your screen and show you whether if it has been successful. To apply any changes hit the hammer. To set breaking points just click next to the line numbers. The program will stop there.
- That's it! You are now connected, all you have to do is press the button to the left of the configuration name (pictured in the first picture of this step, highlighted with red square) to make and reload the project including your changes.
- The first time you do this, a message box pops up asking you to confirm you want to make the changes. It will be easiest if you tick 'Don't show this message again' to speed the process up.
I hope you find this as useful as I do. If you need help make a post on the forum and if I see it I will try to help you out,
IMPORTANT: The default value of timeout-time in spigot.yml is 60. This causes your server to time out if you resume the thread after 60 seconds. To prevent your server from constantly timing out while debugging, set timeout-time to a large number.
The client will still time out after 30 seconds, so if someone knows how to overcome this please edit this wiki!