Wednesday, May 27, 2009

Error launching Mozilla (only from inside Eclipse) using simple Runtime.exec() on Ubuntu.

I discovered that, on Ubuntu 9.04, I cannot launch mozilla browser using the simple invocation of Runtime.getRuntime().exec("/usr/bin/mozilla"). It turns out, I have to use the variant of exec() where I can pass in some environment variables explicitly.

Here is the program that I used to test it:
import java.io.IOException;

public class MB {

/**
* @param args
*/
public static void main(String[] args) {
try {
Process exec = Runtime.getRuntime().exec("/usr/bin/mozilla"
// Uncommenting out following line will launch mozilla browser on Ubuntu
//, new String[] {"DISPLAY=:0.0", "HOME="+System.getProperty("user.home")}
);
System.out.println(exec.waitFor());
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
Very interesting. May be that is why Eclipse has trouble launching help in default external browser on Ubuntu.

UPDATE: It turns out that this fails only if I run the above program from inside Eclipse. If I run it from a terminal window it works. It turns out that Eclipse sets an environment variable MOZILLA_FIVE_HOME to point to /usr/lib[64]/xulrunner-addon to make the SWT's embedded browser widget work correctly. However this environment variable is inherited by any process that is launched from within Eclipse. And apparently MOZILLA_FIVE_HOME inteferes with the Mozilla browser (/usr/bin/mozilla) launch.

Two issues have been filed in Eclipse Bugzilla:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=278415
https://bugs.eclipse.org/bugs/show_bug.cgi?id=278296

No comments: