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

Java swing with ROS

asked 2015-04-11 10:40:46 -0600

nouf gravatar image

updated 2015-04-13 07:41:18 -0600


I wan't to ask if there is anyway to connect Java swing with ROS?

For example, When I click on a button, a launch command should be fired.

I used the following code and it works:

try {
            Process p = Runtime.getRuntime().exec("ls");
            BufferedReader in = new BufferedReader(
                                new InputStreamReader(p.getInputStream()));
            String line = null;
            while ((line = in.readLine()) != null) {
        } catch (IOException e) {

But when I tried ROS command it shows the following error: Cannot run program "roscore": error=2, No such file or directory
    at java.lang.ProcessBuilder.start(
    at java.lang.Runtime.exec(
    at java.lang.Runtime.exec(
    at java.lang.Runtime.exec(
    at javaapplication2.JFrame.jButton1ActionPerformed(
    at javaapplication2.JFrame.access$000(
    at javaapplication2.JFrame$1.actionPerformed(
    at javax.swing.AbstractButton.fireActionPerformed(
    at javax.swing.AbstractButton$Handler.actionPerformed(
    at javax.swing.DefaultButtonModel.fireActionPerformed(
    at javax.swing.DefaultButtonModel.setPressed(
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(
    at java.awt.Component.processMouseEvent(
    at javax.swing.JComponent.processMouseEvent(
    at java.awt.Component.processEvent(
    at java.awt.Container.processEvent(
    at java.awt.Component.dispatchEventImpl(
    at java.awt.Container.dispatchEventImpl(
    at java.awt.Component.dispatchEvent(
    at java.awt.LightweightDispatcher.retargetMouseEvent(
    at java.awt.LightweightDispatcher.processMouseEvent(
    at java.awt.LightweightDispatcher.dispatchEvent(
    at java.awt.Container.dispatchEventImpl(
    at java.awt.Window.dispatchEventImpl(
    at java.awt.Component.dispatchEvent(
    at java.awt.EventQueue.dispatchEventImpl(
    at java.awt.EventQueue.access$300(
    at java.awt.EventQueue$
    at java.awt.EventQueue$
    at Method)
    at java.awt.EventQueue$
    at java.awt.EventQueue$
    at Method)
    at java.awt.EventQueue.dispatchEvent(
    at java.awt.EventDispatchThread.pumpOneEventForFilters(
    at java.awt.EventDispatchThread.pumpEventsForFilter(
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(
    at java.awt.EventDispatchThread.pumpEvents(
    at java.awt.EventDispatchThread.pumpEvents(
Caused by: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(
    at java.lang.ProcessImpl.start(
    at java.lang.ProcessBuilder.start(

UPDATE: bash -c roscore produce no errors but nothing works ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-04-11 13:51:24 -0600

ahendrix gravatar image

updated 2015-04-14 03:25:42 -0600

no such file or directory usually indicates that you don't have your PATH environment variable set up correctly.

Have you sourced your ROS or setup.bash before you run your Java application?


The setup.bash script does not take arguments; running setup.bash roscore is incorrect.

Assuming you have your default bashrc set up to source the ROS setup.bash, running bash -c roscore should result in a running roscore. The docs for Runtime.exec) say that it executes the command in a separate process; are you sure it isn't doing anything?


Does your .bashrc source your ROS setup.bash?

You should probably also be checking the process state for the process you spawn, to make sure that it is running, you should check the error output to see if there's anything useful there, and you should check the return code when the process is done, to see if it returned with an error.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-04-11 10:40:46 -0600

Seen: 278 times

Last updated: Apr 14 '15