Skip to content

Developing a Java Module

Paul Friederichsen edited this page Nov 2, 2015 · 3 revisions

It is highly recommended to read the Creating a Module -- Start to Finish guide that covers everything with explanations and screenshots.

Java modules are the most abundant modules for Toast. Java modules run the fastest, have the widest access, and can be packaged nice and neat into a .jar file to be transported.

Getting Started

Developing a Java module is very simple. First of all, download the HotPlate CLI. Once you've setup HotPlate on your OS, you can go ahead and run toast init in your module directory and follow the prompts. This will setup your file structure for Toast and GradleRIO.

If you don't want to use HotPlate and want to manually setup your module, download the Toast Universal release from this repo and extract its contents. Edit the build.gradle file to resemble your own settings and continue on. All future commands starting with toast should instead start with gradlew.bat on windows and ./gradlew on unix (linux/mac).

IDE Setup

Before you can get started writing java code, you need to setup your environment.

Eclipse Users

Eclipse users should run toast eclipse and import the module directory as an existing project in eclipse.

IntelliJ Users

IntelliJ Users should run toast idea and double-click the .ipr file to open IntelliJ to their Toast Project.

Writing your first line of code

Now we can start writing your code. If you're using HotPlate, a class file has already been generated for you. Go ahead and edit this class file so that the robotInit() method contains logger.info("Hello World!"). This should make your Module Class print "Hello World!" to the console when your module is loaded.

Running your Module

HotPlate and Gradle automatically set run configurations for you. In Eclipse, the run configuration is called "{YourModule}-Sim", and in IntelliJ, it is called "{YourModule}-Sim" and is located under the "Launch" folder. Before you run this, make sure an empty folder called "run" exists in your Module Directory, as this is where Toast will store it's files.
Go ahead and launch the Run Configuration and your Simulation Environment should start right up. This is how you test your code before deploying it to the RoboRIO.

Deploying your Code

Deploying your Code is done by running the command gradlew deploy. This will attempt to find your RoboRIO, copy the code over and run it. If you wish to deploy using a USB Stick (recommended), you must run gradlew build and then copy the .jar file under build/libs/ to your USB Stick's toast directory.