Note: This tutorial assumes that you have completed the previous tutorials: Installation, Creating Rosjava Packages.
(!) 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.

Building RosJava Libraries (Catkin Style)

Description: How to create, compile and deploy rosjava libraries (maven artifacts).

Keywords: rosjava

Tutorial Level: BEGINNER

Next Tutorial: RosJava Message Artifacts

This tutorial describes how to create and deploy rosjava libraries (jars) along with an explanation of the mysterious process itself. It assumes that you have a ros-catkin environment from a source or deb installation and have skimmed through the creating rosjava packages tutorial.

Building the Jar

Creating a Gradle Sub-Project

This assumes you have already initialised a catkin-gradle package for your java projects. If you haven't done so already, refer to the Creating Rosjava Packages tutorial.

A catkin_create wizard is available that automagically creates a gradle subproject with the appropriate structure and a dummy class for a library jar.

> source devel/setup.bash
> cd src/rosjava_catkin_package_a
> catkin_create_rosjava_library_project my_java_library
> cd ../..
> catkin_make

You should see it work through the gradle tasks and finally dump the resulting artifact (jar) in our local workspace maven repository (devel/share/maven).

:my_java_library:processResources UP-TO-DATE
Uploading: com/github/rosjava/rosjava_catkin_package_a/my_java_library/0.1.0/my_java_library-0.1.0.jar to repository remote at file:~rosjava_workspace/devel/share/maven/

The actual .jar that resulted from the build process before uploading can be found in my_java_library/build/libs.

Under the Hood

The Gradle Task

When you run catkin_make, cmake runs through your entire workspace and when it gets to your new project, it will pass off the build to gradle. The tasks that gradle builds can be seen listed in your CMakeLists.txt:


In particular, the publishMavenJavaPublicationToMavenRepository task. This creates the rules that eventually publish your jar into the local workspace's maven repository.

Compiling with Gradle

You could alternatively just compile your subproject alone with gradle (much faster than running catkin_make across your entire workspace):

> source devel/setup.bash
> cd src/rosjava_catkin_package_a/my_java_library
> ../gradlew publishMavenJavaPublicationToMavenRepository

You might like to set publishMavenJavaPublicationToMavenRepository as a default task inside build.gradle so you can just call gradlew without arguments.


Inspecting this tutorial's build.gradle illustrates an empty file (ok, just comments). If your classes were to have other rosjava dependencies, you would add them to the dependency closure here.

If you would like to make this library available to other projects, then you would need to add to the dependency closure in those projects.

If it was a sibling gradle subproject:

# build.gradle
dependencies {
    compile project(':my_java_library')

If it was an different catkin-gradle package altogether:

# build.gradle
dependencies {
    compile 'com.github.rosjava.rosjava_catkin_package_a:my_java_library:[0.1,)'

and to make sure catkin_make can sequence your source builds correctly:

# package.xml

Wiki: rosjava_build_tools/Tutorials/indigo/Building RosJava Libraries (last edited 2015-02-18 11:10:52 by DanielStonier)