slasso 27 Share Posted May 11, 2016 Hi everyone, my first tut! This tutorial will teach you how to remotely connect to your dreambot scripts through Eclipse or IntelliJ to be able to pause and step through lines of code one at a time. For the most part, I will be using Eclipse. I don't use IntelliJ but I will go through the steps for it as well. Let's get started. I'm going to assume you have java set up properly to run java commands on a command line or terminal. check with a command like 'java -version'. You should see something like: java version "1.8.0_91" Java SE Runtime Environment (build 1.8.0_91-b14) Java HotSpot 64-Bit Server VM (build 25.91-b14, mixed mode) If you don't see this then you need add JAVA_HOME/bin to your path. Here's brief summaries for this on Windows and Linux: On Windows right click PC->propertoes->advanced system settings->environment variables. Add new variable named JAVA_HOME and path is location of your JDK, ex: 'C:\Program Files\Java\jdk1.8.0_73'. Edit the existing PATH variable and add a new entry '%JAVA_HOME%\bin'. On Linux edit your ~/.bashrc and add JAVA_HOME and update PATH, export etc.. then 'source ~/.bashrc' Now export your script-to-test.jar to your DreamBot\scripts directory like normal. Make sure the compiled jar matches your source code, i.e., don't edit your source after exporting the jar, it will mess up the lines and such when debugging. We are going to open up a DreamBot client.jar through command line with additional flags for debugging. To do this open up a command prompt/terminal in your DreamBot\BotData directory. Now run this command, 'java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=12345 -jar client.jar', as shown below: This will open up DreamBot and open up the port you specify to listen for a debugging program, notice the first line of the output "Listening for transport dt_socket at address: 12345". We will connect to this now in Eclipse/IntelliJ. Eclipse method: Right-click on the project you want to debug and have already exported the latest code into a jar. Click Debug As->Debug Configurations On the left-hand side will be a list of different configurations. Find Remote Java Application and right-click->new In 'Host' make keep it localhost, unless you have dreambot deployed on a remote machine or something, in which case use the hostname of that. In 'Port' enter the port that the client.jar is listening on. In the example above it is 12345 Click Apply->Debug Now to see that eclipse is actually doing something with our dreambot client, go to Window->Perspective->Open Perspective->Debug. We can now see a new box for Debug which has the client running. Now we're able to set breakpoints and run our scripts in DreamBot like normal. You're now connected to your script on debug mode! You can hover over any object to see it's value and fields it has, etc. Step over lines of code, anything. IntelliJ method: Click Run->Edit Configurations Click the + to add a new configuration and select 'Remote'. Name it anything you want. 'Select source using module's classpath' should be your scripts project that you exported the jar for. Change the port to the port you specified earlier. (12345 in my example) Click apply and ok. To set a breakpoint, click in the left margin of a line of code in your script. Click Run-> Debug 'your-debug-config-name' Go to DreamBot and start your script. Your breakpoints should now get triggered. You're now connected to your script on debug mode! Step over lines of code, anything. Debug is a very powerful tool and any developer in Java should always use it. Link to comment Share on other sites More sharing options...
Cardozz 46 Share Posted May 11, 2016 Wow this looks very helpful! However, is there any way you can make/show a video like on how this actually works? I would love to see Link to comment Share on other sites More sharing options...
slasso 27 Author Share Posted May 11, 2016 I could tonight Link to comment Share on other sites More sharing options...
Prison Break 85 Share Posted May 11, 2016 nice man Link to comment Share on other sites More sharing options...
Dreamlicker 750 Share Posted May 11, 2016 I've never done this before, this is really cool. Does this allow the usage of Java Flight Control to monitor resource usage? If not I might make a tut on how to use it for scripts too Link to comment Share on other sites More sharing options...
slasso 27 Author Share Posted May 11, 2016 nice man Thanks (: I've never done this before, this is really cool. Does this allow the usage of Java Flight Control to monitor resource usage? If not I might make a tut on how to use it for scripts too I'm not sure. I've never used that before Link to comment Share on other sites More sharing options...
Hopewelljnj 46 Share Posted May 12, 2016 Wow this is awesome... Been looking for a way to step through script code ever since I hit my first errors! Link to comment Share on other sites More sharing options...
slasso 27 Author Share Posted May 13, 2016 I fixed a typo in the command. The debug args have to be first before the -jar flag or it won't work. java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=12345 -jar client.jar Link to comment Share on other sites More sharing options...
raptor 10 Share Posted July 10, 2016 If you use IntelliJ (and probably for Eclipse too), you can take this further.You can create a Debug Config that builds your script and launches DreamBot with remote debug, so the output gets piped directly to your IntelliJ console. Make an executable script to launch Dreambot in debug mode Open new text file Insert the remote debug command. I used the modern JDK argument: java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar client.jar Save as .cmd on Windows Place in Dreambot BotData directory Make new "Remote" run/debug configuration in IntelliJ Make sure your port matches the port from the remote debug command Add "Build Artifacts" to the "Before launch" section and select your script Add "Run External Tool", then add a new tool Under "Program", select the file you saved as .cmd Now when you run that configuration the IntelliJ console is used for the debug output. It's much quicker to launch everything and immediately get debug feedback. Link to comment Share on other sites More sharing options...
Hopewelljnj 46 Share Posted July 10, 2016 If you use IntelliJ (and probably for Eclipse too), you can take this further. You can create a Debug Config that builds your script and launches DreamBot with remote debug, so the output gets piped directly to your IntelliJ console. Make an executable script to launch Dreambot in debug mode Open new text file Insert the remote debug command. I used the modern JDK argument: java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar client.jar Save as .cmd on Windows Place in Dreambot BotData directory Make new "Remote" run/debug configuration in IntelliJ Make sure your port matches the port from the remote debug command Add "Build Artifacts" to the "Before launch" section and select your script Add "Run External Tool", then add a new tool Under "Program", select the file you saved as .cmd Now when you run that configuration the IntelliJ console is used for the debug output. It's much quicker to launch everything and immediately get debug feedback. On this note you can also do something really simple which saves a lot of typing when testing without building. Right click inside botData folder right click and hit create shortcut. In the option for typing in the shortcut you type in the command that would be entered in cmd. This will open cmd and start the client with remote debugging Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.