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 answers.ros.org. 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

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

Keywords: rosjava

Tutorial Level: BEGINNER

Next Tutorial: Writing a Publisher and Subscriber

Overview

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):

/src
  /rosjava_catkin_package_a
    /rosjava_gradle_subproject_a
    /rosjava_gradle_subproject_b
    /rosjava_gradle_subproject_c
  /rosjava_catkin_package_b
    /rosjava_gradle_subproject_d
    /rosjava_gradle_subproject_e
    /rosjava_gradle_subproject_f

Preparation

You will need a ros environment for your rosjava installation to utilise these scripts. Specifically, after installation (as described in the previous link), the example below will only work after running source rosjava/devel/setup.bash or something equivalent.

RosJava Catkin Packages

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_a
> 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

Wiki: rosjava_build_tools/Tutorials/hydro/Creating Rosjava Packages (last edited 2014-12-28 06:39:38 by AnisKoubaa)