[Documentation] [TitleIndex] [WordIndex

Create custom_msg_or_srv.jar

Instructions in building a .jar for rosjava to handle ROS msgs and ROS srvs. In summary, we will checkout and setup a rosjava environment in order to modify the rosjava_messages to build jar files of your custom messages and/or services.

Setup

Pre-req: ROS-hydro installed

sudo apt-get install --upgrade rosinstall

Create rosjava workspace

Create a parallel rosjava workspace from your catkin workspace

mkdir ~/rosjava_ws  
cd ~/rosjava_ws 
rosws init
rosws merge /opt/ros/hydro/.rosinstall

Checkout rosjava src

git clone -b hydro https://github.com/rosjava/rosjava.git
rosws merge rosjava/rosjava.rosinstall
rosws update

Remove rosjava_test_msgs

rosjava_test_msgs throws a weird bug. To avoid do the following:

Edit package.xml

Remove any ROS packages listed in package.xml file that you don't want to export. Then add the ROS package you are interested in exporting its messages and/or services. The file should look something like this:

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>rosjava_build_tools</build_depend>
  <build_depend>rosjava_bootstrap</build_depend>

  <build_depend>your_ros_package</build_depend>

  <run_depend>rosjava_build_tools</run_depend>
  <run_depend>rosjava_bootstrap</run_depend>

Note: your_ros_package probably lives in a catkin workspace which is separate from this rosjava workspace. Make sure you can access that package. e.g. roscd your_ros_package should work.

Build and Export .jar

./gradlew build  

My successful run in exporting the ros_package appl looks like:

Total time: 2.399 secs
user@ubuntu: ~/rosjava_ws/rosjava_messages$ ./gradlew build
:rosjava_messages is spawning subprojects: [appl]
:appl:bugfixtask
:appl:generateSources
:appl:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.6
1 warning
:appl:processResources UP-TO-DATE
:appl:classes
:appl:jar
:appl:assemble
:appl:compileTestJava UP-TO-DATE
:appl:processTestResources UP-TO-DATE
:appl:testClasses UP-TO-DATE
:appl:test UP-TO-DATE
:appl:check UP-TO-DATE
:appl:build

BUILD SUCCESSFUL

Note: ./gradlew tasks gives a helpful list of gradle commands

You will now find an exported .jar of your_ros_package that contains .class files of the messages and services defined in your package:

cd rosjava_messages/your_ros_package/build/libs/

2024-11-09 17:35