1

In Java 5, is there a default way to pass a URL to the system and have it launch the application associated with it? For example http:// links would usually open IE or Firefox, but things like itms:// should open iTunes.

If possible I would rather not use Runtime.exec() to start some external process directly, because this would be platform specific. If there is no other way, what would I call for Windows/OS X and Linux to cover the most popular ones?

1

6 Answers 6

4

Use the Java Desktop API

 Desktop desktop =  Desktop.getDesktop();
 if (desktop.isSupported(Desktop.Action.BROWSE)) {
     desktop.browse(uri);
 }
Sign up to request clarification or add additional context in comments.

1 Comment

I don't think that was added until Java 6.
2

I agree with ivan that Java Desktop API would work, but it's 6 only.

I know how to do it on Windows (it involves executing rundll32.dll), but I did some quick Googling and this link seems like your best shot.

Hope that helps.

Comments

1

For Java 5, try JDIC. It has cross-platform support for opening the OS's registered application for a file. If I remember correctly, this formed the basis for the similar API added in Java 6.

Comments

1

BrowserLauncher does what you need.

Comments

0

Windows it's "start [URI]", OSX it's "open [URI]", Linux has no equivalent as it all depends upon their window manager.

As for whether itms:// opens iTunes, that all depends on their configuration.

Ivan's answer appears much better than mine.

Comments

0

Looks like you want java.awt.Desktop but I think it was introduced in 1.6 and wasn't available in 5...:-(

Comments

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.