Note: This tutorial assumes that you have completed the previous tutorials: Anatomy of a RosJava Package, Installation.
(!) Please ask about problems and questions regarding this tutorial on Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Creating Rosjava Packages (Catkin Style)

Description: Script wizards for conveniently creating rosjava packages and projects.

Keywords: rosjava

Tutorial Level: BEGINNER

Next Tutorial: Writing a Publisher and Subscriber


This tutorial will teach you how to use the catkin_create_rosjava_xx scripts to populate rosjava packages and subprojects. A typical workspace will look like (refer to anatomy of a rosjava package for more details):



You will need a ros environment to utilise these scripts as we will be creating (ros) catkin style rosjava packages. Note that this isn't the only way to build on top of rosjava - you can also create regular java projects, but this tutorial will not detail that here.

After installation from source or debs, the example below will only work after sourcing ~/rosjava/devel/setup.bash or something equivalent.

RosJava Catkin Packages/Gradle Projects

Create an empty workspace and populate it with a couple of rosjava catkin packages:

> mkdir -p src
> cd src
> catkin_create_rosjava_pkg rosjava_catkin_package_a
> catkin_create_rosjava_pkg rosjava_catkin_package_b
> cd ..
> catkin_make
> source devel/setup.bash

At this point, there is nothing yet to compile, so catkin_make just configured a setup.bash for you. A single rosjava catkin package includes the following important files:

  • CMakeLists.txt: configures gradle builds under the hood and sets up install rules.

  • package.xml : used to string/sequence compilation of separate gradle projects with catkin_make.

  • build.gradle : the (super) project gradle build rules customised for rosjava.

  • settings.gradle : the place to list all your subprojects (like CMake's add_subdirectory).

RosJava Gradle Subprojects

Binary Projects (App)

Create a simple example application with talker and listener.

> cd src/rosjava_catkin_package_a
> catkin_create_rosjava_project rosjava_gradle_subproject_a
> cd ../..
> catkin_make

For more details about java binary (app) projects, continue with the Writing a Simple Publisher and Subscriber Tutorial.

Library Project (Jar)

Create a simple library jar with a single compiled class, Dude.

> cd src/rosjava_catkin_package_a
> catkin_create_rosjava_library_project rosjava_gradle_subproject_b
> cd ../..
> catkin_make

For more details about java library projects, continue with the Building RosJava Libraries Tutorial.

Message Projects (Msg)

With regards to creating msg projects, you might wish to read the rosjava documentation on how rosjava handles messages and in particular unofficial message packages.

Faster Compiles

You can of course keep doing entire workspace recompiles every time you make an edit with catkin_make, but you can speed things up. Just as running make in build project folders for c++ will only make the targets you're interested in, you can do the same for rosjava with gradle.

  • Source devel/setup.bash - this makes sure all the environment variables are correctly set.

  • From the root of your gradle super projects run './gradlew tasks' and pick the task you want to build (hint: check CMakeLists.txt).
  • From a gradle subprojects, use '../gradlew' instead.

Video Tutorial

The following video describes the process for hydro, but it is relatively similar for indigo.

Wiki: rosjava_build_tools/Tutorials/indigo/Creating Rosjava Packages (last edited 2018-03-08 12:37:11 by jubeira)