ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Writing a Simple Publisher and Subscriber (Java)

asked 2014-01-23 13:44:26 -0600

updated 2014-01-31 07:23:19 -0600

I'm going through the three rosjava tutorials at .

I successfully reached the end of Creating Rosjava Packages, and I am now attempting to fill in apparent gaps between that tutorial and the third, Unofficial Messages.

Specifically, I am hoping to find a Java version of Writing a Simple Publisher and Subscriber (C++) and Writing a Simple Service and Client (C++), along with information about running the resultant Java-based nodes, as in the associated "Examining" tutorials that follow those above.

Could someone point me in the right direction or verify that such information is not yet available?

edit retag flag offensive close merge delete


What was the blocker here at this last step?

Daniel Stonier gravatar image Daniel Stonier  ( 2014-01-24 12:25:16 -0600 )edit

FYI, the above comment was only relevant to an intermediate version of this question. See my answer below for a link to the directions I was seeking.

bradknox gravatar image bradknox  ( 2014-01-31 16:32:32 -0600 )edit

4 Answers

Sort by ยป oldest newest most voted

answered 2014-01-31 07:28:08 -0600

After discussing this question with Daniel Stonier over email, I received directions that got me to (1) having a compiled publisher and a compiled subscriber and (2) running them as ROS nodes.

I added a tutorial page that documents the additional steps needed. The page is Writing a Simple Publisher and Subscriber (Java) and is now in the tutorial sequence at .

edit flag offensive delete link more

answered 2014-01-23 14:54:26 -0600

Hi, this link contains links to getting started documentation relating to rosjava core and android core, mainly for porting ros applications to android. It has the basic examples you are after.

I've used these guides when the released early 2013, if there is an update to rosjava, these should still be relevant.

edit flag offensive delete link more


Thanks, Peter. I found some newer documentation at, covering rosjava_core 0.1.6 (instead of 0.0.0). In particular, "Getting Started" gives helpful code, though it seems to not cover all of the current rosjava features (e.g., no catkin_make).

bradknox gravatar image bradknox  ( 2014-01-24 09:10:04 -0600 )edit

The rosjava docs pretty much concentrate on java-gradle workflows right now, the wiki docs cover the various ways you can integrate rosjava (sources or debs in a ros environment or a totally non-ros maven environment).

Daniel Stonier gravatar image Daniel Stonier  ( 2014-01-24 12:27:33 -0600 )edit

I was building for Android deployment so gradle for build was about as much as I used the gradle system except if I created a new msg. One thing that didn't work in ROSJava 0.0.0 was the Action Server and messages. Do you know if it works now? Otherwise you'll have problems integrating.

PeterMilani gravatar image PeterMilani  ( 2014-01-30 14:40:05 -0600 )edit

answered 2014-01-30 20:13:12 -0600

uzair gravatar image

I was also facing the same problem. So I just downloaded the entire rosjava_core-hydro folder from github . This folder contains another sub folder called rosjava_tutorial_pubsub. Now when you enter into the build folder of this package you will find that the path matches exactly with what is given on the snapshot documentation which is

source your devel/setup.bash roscd rosjava_core cd rosjava_tutorial_pubsub ../gradlew installApp roscore & ./build/install/rosjava_tutorial_pubsub/bin/rosjava_tutorial_pubsub org.ros.rosjava_tutorial_pubsub.Talker

You can now run these commands and see hello world being passed from your to

edit flag offensive delete link more



This is exactly the kind of answer I would have needed if Daniel Stonier didn't help me work with the deb installation. I expect it will be useful for others to see. Thanks!

bradknox gravatar image bradknox  ( 2014-01-31 07:29:42 -0600 )edit

answered 2014-01-24 12:24:51 -0600

Daniel Stonier gravatar image

updated 2014-01-28 22:59:36 -0600

The catkin_make and gradle workflows are compatible, but probably haven't been explained very well. There was just a very brief comment on the installation page. I just added a section to the creating rosjava packages tutorial. I'll paste below just in case that link ever moves:

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.

Some extra information on getting to the point of being able to provide the finishing touches of an executable java project are being discussed in this thread on the ros-sig-java google group.

edit flag offensive delete link more


Thanks, Daniel. Your answer adds clarity to the build process.

bradknox gravatar image bradknox  ( 2014-01-27 08:17:25 -0600 )edit

Question Tools

1 follower


Asked: 2014-01-23 13:44:26 -0600

Seen: 4,779 times

Last updated: Jan 31 '14