Difference between revisions of "Robocode/Eclipse/Running from Eclipse"

From Robowiki
Jump to navigation Jump to search
m (MultiplyByZer0 moved page Robocode/Running from Eclipse to Robocode/Eclipse/Running from Eclipse: Bring this page in line with all other Eclipse documentation)
(Added page to explain how to setup Intellij with Robocode)
Line 1: Line 1:
Wondering how to run your robot in [[Robocode]] from [http://www.eclipse.org/ Eclipse]? Well this is possible! And that is what this page is all about.
+
Wondering how to run your robot in [[Robocode]] from [https://www.jetbrains.com/idea/ Intellij]? Well this is possible! And that is what this page is all about.
  
== Running your robot from Eclipse ==
+
Make sure Robocode is installed and can run before continuing.
Right-click on your project, move the mouse-pointer down to '''Run As''' in the menu that opens and click '''Run...'''.
 
  
[[Image:Eclipse-RunAs.png|Shows how to start running a robot by right-clicking on the robot project, and then select "Run..." from the "Run As" item on the popup menu that occurs in Eclipse]]
+
== Create a new Intellij project ==
 +
Create a new Java project in Intellij.
 +
Nothing special about it. I am using JDK 1.8, I don't think this matters.
  
 +
== Add Robocode's library + javadocs to Intellij ==
 +
Right click your top level module/folder in intellij. Select "Open Module Settings" (or press F4).
 +
Go to libraries, and add a Java library.
 +
Navigate to where you installed Robocode and select both the "libs" and "javadoc" folder.
 +
Apply, Okay, exit.
  
Now the following window will show up:
+
== Create Your Package + Robot ==
 +
Right click the src folder on the right.
 +
Add a package.
 +
In the package, add a java class.
  
[[Image:Eclipse-RunJavaApplication.png|Shows the Run dialog where the user must first press the "New" button, and then click "Java Application" to create a launch configuration for the robot]]
+
import robocode.Robot, and write a class that extends Robot.
 +
Intellij should be autocompleting for you at this point.
  
 +
== Build and use your robot ==
 +
Build your file. You should see a new folder appear in your project. out > production > projectName > packageName > robotClassName
  
Click on the '''Java Application''' on the left side, and afterwards the '''New''' button (New launch configuration).
+
Load up Robocode, go to Options > Preferences > Development Options
 +
Add the path to your intellij build output. Specifically /path/to/intellijProjectName/out/production/projectName
 +
If you don't add this exact path, it won't work.  
  
Now you should change the name of your launch configuration to something you remember, e.g. '''MyRobots - Robocode'''.
+
When you start a battle, in the robot selector, you should see your robot appear under your package name!
  
In the '''Main class''' field you must write '''robocode.Robocode''', which is the main class of [[Robocode]] used for playing the game.
+
== Running your robot from Intellij ==
 +
Edit your run configurations.
 +
Create a new run configuration of type "Application".
  
[[Image:Eclipse-RunConfigMain.png|Shows the Run dialog's run configuration details for the Main pane, where the name of the launch configuration must be typed in]]
+
Hit the blue "Modify Options" text on the right, select "Add VM options".
 +
Make sure you fill out the following:
 +
java version: java 8 SDK
 +
main Class: robocode.Robocode
 +
VM options: -Xmx512M -Dsun.io.useCanonCaches=false -Ddebug=true
 +
Working directory: path/where/you/installed/robocode
  
 +
Save this.
  
Next, you must click on the '''Arguments''' tab.
+
Now add some breakpoints, hit the debug icon in intellij.  
 
+
It should load up robocode. When you start a battle with your bot, it will stop on the debug points!
Here you write <code>-Xmx512M -Dsun.io.useCanonCaches=false -Ddebug=true</code> into the '''VM arguments''' text box. The <code>-Xmx512M</code> tells the Java VM that Robocode can use up to maximum 512 MB RAM off the heap, -Ddebug=true tells Robocode that it should not give you skipped turns just because you paused robot in debugger, and <code>-Dsun.io.useCanonCaches=false</code> is a workaround to prevent SecurityExceptions to occur when robots try to access a file.
 
 
 
Finally, you must click on the '''Other''' radio button under '''Working directory''', and then write the full path to the folder where [[Robocode]] is installed in the text file beside '''Other'''.
 
 
 
[[Image:Eclipse-RunConfigArguments.png|Shows the Run dialog's run configuration details for the Arguments pane, where the text field path for "Other:" under "Working Directory" must be typed in]]
 
 
 
 
 
Now you press "Run", and Robocode will (hopefully) start up. In Robocode you start your robot by selecting Battle->New from the menu or by using the hotkey Ctrl+N. Next, you select your robot and some other opponent robots, and press "Start Battle".
 
 
 
The next time you want to run your robot(s) in Robocode from Eclipse, you simply run your launch configuration like this:
 
 
 
[[Image:Eclipse-RunMyRobots.png|Shows the popup menu that occurs when the user selects the "run" button in Eclipse, where MyRobots launch configuration must be selected in order to run it]]
 
 
 
 
 
An easier way is just to click on the "green play button" without the popup menu. This will start the last launch configuration automatically, which should be your project.
 
 
 
== References ==
 
* [http://www.eclipse.org/ Eclipse.org - Eclipse home page]
 
* [http://www.eclipse.org/downloads/ Eclipse Downloads]
 
* [http://download.eclipse.org/eclipse/downloads/ Eclipse project downloads - latest releases]
 
  
 
== See also ==
 
== See also ==
 
=== Using Eclipse IDE ===
 
* [[Robocode/Eclipse|Using Eclipse as IDE]]
 
* [[Robocode/Eclipse/Create_a_Project|Creating a project for your robots]]
 
* [[Robocode/Add_a_Robot_Project|Add robot project from an IDE into Robocode]]
 
* [[Robocode/Eclipse/Create_a_Robot|Creating a robot in Eclipse]]
 
* [[Robocode/Eclipse/Debugging Robot|Debugging your robot with Eclipse]]
 
  
 
=== Robot API ===
 
=== Robot API ===

Revision as of 23:21, 3 October 2023

Wondering how to run your robot in Robocode from Intellij? Well this is possible! And that is what this page is all about.

Make sure Robocode is installed and can run before continuing.

Create a new Intellij project

Create a new Java project in Intellij. Nothing special about it. I am using JDK 1.8, I don't think this matters.

Add Robocode's library + javadocs to Intellij

Right click your top level module/folder in intellij. Select "Open Module Settings" (or press F4). Go to libraries, and add a Java library. Navigate to where you installed Robocode and select both the "libs" and "javadoc" folder. Apply, Okay, exit.

Create Your Package + Robot

Right click the src folder on the right. Add a package. In the package, add a java class.

import robocode.Robot, and write a class that extends Robot. Intellij should be autocompleting for you at this point.

Build and use your robot

Build your file. You should see a new folder appear in your project. out > production > projectName > packageName > robotClassName

Load up Robocode, go to Options > Preferences > Development Options Add the path to your intellij build output. Specifically /path/to/intellijProjectName/out/production/projectName If you don't add this exact path, it won't work.

When you start a battle, in the robot selector, you should see your robot appear under your package name!

Running your robot from Intellij

Edit your run configurations. Create a new run configuration of type "Application".

Hit the blue "Modify Options" text on the right, select "Add VM options". Make sure you fill out the following: java version: java 8 SDK main Class: robocode.Robocode VM options: -Xmx512M -Dsun.io.useCanonCaches=false -Ddebug=true Working directory: path/where/you/installed/robocode

Save this.

Now add some breakpoints, hit the debug icon in intellij. It should load up robocode. When you start a battle with your bot, it will stop on the debug points!

See also

Robot API

Tutorials

News and Releases

Home pages