1

I am using

java.awt.Desktop.getDesktop().browse(uri);

to show my users a generated html file. All is fine if the browser (firefox 3.5.7; linux) is started before I make the call. But if the browser start is triggered from the getDesktop().browse call then the java application will not exit until the browser closes.

How can I avoid this behaviour? Is this known under windows/macOsx too?

(If I then force the exit of the java application the browser will close too and sometime even crash!?)

2 Answers 2

2

The reason the browser exists is because the browser is launched as a dependent process...so when the first process shuts down, all its dependent processes are shut down with it. But in the case when you start the browser first, it already has a different process ID that isn't affected by your application. I think the only way to avoid this behavior is to use a different technique (perhaps Runtime.exec()?) to launch the browser in a way that registers it as a non-dependent process.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, thanks! that did the trick. I am usining now the code here: centerkey.com/java/browser (of course without the fallback version to jse6 or I will fallback to jse6 if the other calls do not work :-))
1

The project Browser Launcher (http://browserlaunch2.sourceforge.net/) can be the solution for your problem. You can launch a browser from your code like this:

String url = "http://....";
BrowserLauncher() launcher = new edu.stanford.ejalbert.BrowserLauncher();
launcher.openURLinBrowser(url);

1 Comment

This has one drawback. In future, if you plan to turn to "webswing", then webswing does not support BrowserLauncher(). It possibly, does support java.awt.Desktop, as per documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.