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

[rosjava] Error using rosrun

asked 2018-10-10 14:50:07 -0600

rezenders gravatar image

I am trying to learn how to use rosjava. I am following the official tutorial, however in the second part Creating and Running Talker-Listener I am having some trouble.

When I run:

rosrun rosjava_catkin_package_a my_pub_sub_tutorial com.github.rosjava.rosjava_catkin_package_a.my_pub_sub_tutorial.Talker

I get the following error:

Loading node class: com.github.rosjava.rosjava_catkin_package_a.my_pub_sub_tutorial.Talker
Exception in thread "main" org.ros.exception.RosRuntimeException: Unable to locate node: com.github.rosjava.rosjava_catkin_package_a.my_pub_sub_tutorial.Talker
        at org.ros.RosRun.main(RosRun.java:56)
Caused by: java.lang.ClassNotFoundException: com.github.rosjava.rosjava_catkin_package_a.my_pub_sub_tutorial.Talker
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at org.ros.internal.loader.CommandLineLoader.loadClass(CommandLineLoader.java:239)
        at org.ros.RosRun.main(RosRun.java:54)

Also, is it necessary to use catkin_create_rosjava_project my_pub_sub_tutorial ? Is it possible to run programs the same way it is done with python? Like just creating a file.py and adding permissions to run?

Ps: I have very little knowledge about java.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-10-30 15:37:32 -0600

jubeira gravatar image

Hi @rezenders,

The error is because the class you are trying to execute is not in the classpath.

Also, is it necessary to use catkin_create_rosjava_project my_pub_sub_tutorial ? Is it possible to run programs the same way it is done with python? Like just creating a file.py and adding permissions to run?

The short answer is no.

Let me explain a bit: every Java program has a fixed entrypoint (aka main method) that is the first thing executed. In rosjava you regularly write a ROS node overriding AbstractNodeMain, so you need some main method to actually run the node for you. That is provided in RosRun class, which is the standard entrypoint for any rosjava application (look at the project level build.gradle file; you should see mainClassName declared there). When you execute the command rosrun [package] [project] [class name] you are actually calling an executable script generated by Gradle, which runs RosRun class (which is part of rosjava), which in turn loads your node to the classpath and executes it. There are some more details around all of this, but as you can guess it's not the same as executing a python script.

Did you follow the steps of the tutorial one by one without skipping anything? You shouldn't encounter any errors there.

edit flag offensive delete link more

Comments

@rezenders did that work for you?

jubeira gravatar image jubeira  ( 2018-11-21 10:28:12 -0600 )edit

It worked, I was making a mistake. Thank you for you explanation!

rezenders gravatar image rezenders  ( 2018-12-12 14:25:50 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2018-10-10 14:50:07 -0600

Seen: 326 times

Last updated: Oct 30 '18