Plugin testing in IDE realtime

I know that somewhere around is a description about how to setup Eclipse etc with the entire github cloned development code and such to run the server through it, in such a way that we can do the realtime debugging and hot-swapping of plugin code like is so coolly shown in the videos. I also remember doing this in bukkit in the very early part of plugin coding, but it wasn’t anywhere as involved as having the github project - it just used the jar files downloadable but did work… cant recall or find out how that was again, but…

Is it possible do the ide setup to run the server, without having the entire live-development project code for everything, instead using regular spongeforge, forge and the asociated minecraft jar files only. It would be nice to bypass the long startup to race to see if the plugin change works or blows up something, for n-successive tweaks of something, but without doing the whole thing of emulating a sponge developer setup. Plus, i prefer to code with a fixed known pair of servermod/server/api files in case i stuggle with chaging things, and while in the middle of that struggle, suddenly a change in the api code or servercore code happens that touches on what im struggling, and then left more confused - id rather resolve it, then update the jars, then see if it works still or has changes now, when im expecting something might happen…

You can very well start up a SpongeForge server by adding the debugging JVM flags to launch it. Then your IDE could go through it and such. Correct me if I’m wrong @Zidane

1 Like

There are multiple ways how to achieve this.

The most common is to start vm with debug arguments.

-Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n

If you dont want to (or from some reasons can’t) start a process with arguments above you can use jsadebugger. http://docs.oracle.com/javase/7/docs/technotes/tools/share/jsadebugd.html

1 Like

Will give this a try…
EDIT: modified my bat file to do that, by adding as the switches to what i already had, and it lauched the game server fine, noted that it was active [Listening for transport dt_socket at address: 5005 ]

But, unable to see any way for Eclipse to hook anything from the server… Also, not sure how running the server with a plugin jar file will assocate to the ide that im wanting to debug that particular plugin.

My gut says the missing thing is associateing eclipse and the server launcher together…

In Eclipe and IntelliJ you can add a “remote application” as a debug application - tell it what port to connect to, 5005 in this case, and then you can debug to your hearts content on any app.

http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-remotejava_launch_config.htm

Managed to set it up (somewhat) with that info – bat file has the flags for port 5005, setup the debug attach feature to the remote server… i can pull up the threads, i put a breakpoint in my plugin to test , it hits the breakpoint just fine, before crashing the server a bit later before i canget back to it…

The part that may or may not have a bearing to do with it is that much of the functions in the thread stack are core server code, and when even accidentally clicking on one of them, the page shows that the source code cant be found. Is this a cause or a red-herring in the process, really not necessary (just empty space to ignore) Otherwise, I will see how to go about making a change/monitoring things without the server crashing due to taking too long, fiddle for a bit - cause it does look like it will make a difference if the server doesnt go down, otherwise, im back to restarting after each change anyways :smile:

@NeumimTo, @ZephireNZ , @gabizou

Thank you very much for putting me on the right track, guys! Just in time too, I was doing something with particle effects that required tweaking-from-hell of a few things to get the right visual effect - movement vectors, positions, parametric equation adjustments. – and I figure I must have edited, tested, and redited withini seconds for at least 45 mins straight. Averaging about 7 changes per minute, that was about 315 cycles. Rebooting the server, that same process cycle would have been about 45 seconds long each time, and required almost 240 minutes or 4 hours! (of course, i would have likely made three effects side by side with changes in parallel to further tweaking, but at some point still losing the overall momomentum with “hurry up!” thoughts pushing the potential next idea out of my mind… :wink:

It allowed me to be ‘picky’ about tweaking somethinig to just-right conditions, and in other cases, to step through new event additions strategically in just a few minutes instead of 20, so the gain as much as it is time, is more about the avoidance of loss of momentum of new ideas, new code to try carefully adding stepwise, new ideas to impliment into a plugin when the time and energy is there to surge for acouple hours.

I am TheBoomer, and this is my testimonial :smiley:

Maybe you can explain what steps you took to get it working from beginning to end? I can see this being really helpful to many other people, myself included.

@DsRulesAll - More than happy to. There are likely many varations that will work, but, this approach is what I did:

First, I modified my launcher .BAT file command to add the flags NeuminTo showed to my existing startup memory flags flags, giving:

"%MyJavaPathVariablePathGoesHere%\java.exe" -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n -Xmx3G -Xms1024M -jar forge-1.8-11.14.3.1543-universal.jar

Then launch the server.

Then, in Eclipse, select **Run **menu, select Run/Debug configurations, select Remove Java Applications.
Click the “New” button-icon to generate 3 tabs of settings…

Specify a **Name **for the app (ie SpongeforgeServer).
Leave project blank.

Connection type: Standard socket attach
host: localhost * << this can be a different ip from your computer if you roll that way*
port: 5005 << Same one added to the launcher bat command

That’s it. The config will be saved under the name specified, hit debug and it will open a connection.

Switch to your Debug perspective and fiddle with the layout.
You can now make changes to your code, save, and it is hot-swapped to the server. It only updates when you save.

Provided you don’t generate and save syntax errors in the code when making changes, or change method names, you can continuously edit-and-save=swap the code on the server. Syntax errors, changed methods -> hot swapping ends (and server usually freezes up and dies)

Despite what your code source will show on screen***, the plugin jar file on the server is the initial state of the code.running on it ***(naturally) So if you make lots of file changes but don’t replace the jar, when it comes time to need to reboot the server, the server wont be running the project source code… But after reconnecting the debugger to it, just add a space somewhere in your file to force a ‘dirty file’ state to allow you to save the files again, and you’re code is in synch again with server.
If the server terminates, or the connection severed by the debugger, it may still appear as a connection but to a terminated service.

After restarting the server from a crash/recovery OR when you sit down to start working a new session, simply pick Run menu–> Debug and it should force refresh the connection, but sometimes it may throw errors due to sticking on a terminated link. If that happens, select the Disconnect entry from context menus or Run menu to clear the debug link, then the run->debug will fetch a fresh connection, and you’re good to go.

====

*Struggle-Saver hint: * Keep in mind that even with you making changes, the server / plugin is not resetting. If you have classes with static features ie a builder or helper function class, and an initialization routine that is only called once for it, any changes in that initialization routine will not take effect on the server since you are merely live-editing a method that is never run again until the server is rebooted.

4 Likes