Most likely you have not setup your environment correctly. The Java program could be using a 'clean' shell to execute your command, while in your shell you've sourced the relevant setup.bash
.
I'm not sure whether it is enough to run the Java program from a shell in which you've sourced setup.bash
or if you need to configure the methods you use to invoke roscore
in such a way that the embedded shell is configured correctly. I'll leave that for you.
Edit:
I'm sorry... is there anything that u suggest I could do to fix the problem? if there's any.. could you please be specific with the steps? I cannot understand what u r saying.
This is all rather unrelated to ROS, but: for java.lang.ProcessBuilder
the following can be found in the documentation:
This class is used to create operating system processes.
[..]
Each process builder manages these process attributes:
[..]
- an environment, which is a system-dependent mapping from variables to values. The initial value is a copy of the environment of the current process (see System.getenv())).
So it would appear that at least ProcessBuilder
will pass on the entire environment of the shell the Java program was started in to the shell that is used to start your roscore
in. That means that it should be sufficient to start your program in a shell where you've already done source /opt/ros/fuerte/setup.bash
, and everything "should work".
In case of Eclipse, starting it from the shell (terminal window) where you sourced setup.bash
should also work. You can do that using /path/to/eclipse/installation/eclipse
.
If you cannot do that (because of deployment or whatever), you can use ProcessBuilder
's methods to setup the required environment variables first, and then start roscore
. This is documented at the end of the intro in the documentation of ProcessBuilder
:
ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2");
Map<String, String> env = pb.environment();
env.put("VAR1", "myValue");
env.remove("OTHERVAR");
env.put("VAR2", env.get("VAR1") + "suffix");
pb.directory(new File("myDir"));
Process p = pb.start();