wood burning stoves 2.0*
The moose likes Java in General and the fly likes Launching firefox and IE from a Java App Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Launching firefox and IE from a Java App" Watch "Launching firefox and IE from a Java App" New topic
Author

Launching firefox and IE from a Java App

Dar Var
Ranch Hand

Joined: Oct 12, 2004
Posts: 74
I have a Java app downloaded using Java Web Start that creates html by transforming xml using xsl.

I need to open the html in either Firefox or IE.

1. Firstly is there any way to tell the app which Browser launched the Java Web Start .jnlp file?

2. How can you launch Firefox or IE from a Java app? Is there any API available?

3. Preferably I do not want to save the html file to disk. Can it be passed directly from the Java app to the Browser?

Thanks ins advance.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


1. Firstly is there any way to tell the app which Browser launched the Java Web Start .jnlp file?

Don't think so. You don't need a broswer to launch a Java Web Start app, so I don't think there is any out-the-box method of doing this. Even if there were, I'm not sure how it would help solve your issue.


2. How can you launch Firefox or IE from a Java app? Is there any API available?

Runtime.exec(). Presuming you know where the user has installed their browser. And which browser it is.



3. Preferably I do not want to save the html file to disk. Can it be passed directly from the Java app to the Browser?

You can't use a browser to open a file that doesn't exist. Lots of Swing components render HTML though - could you not just use a one of them in your app?
[ January 25, 2007: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
One note with runtime exec ... on Windows you can "execute" an HTML file and launch the default browser. Open a command window and type the name of an existing HTML file like a command to see it work. There are many examples using RUNDLL32 to launch a file like this:

Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
If you're using JDK 6, you can launch a browser fairly easily with java.awt.Desktop:

[ January 25, 2007: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
In fact, the BasicService class that comes with Webstart has a showDocument method that does exactly what you want: http://java.sun.com/products/javawebstart/docs/javadoc/javax/jnlp/BasicService.html


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
jQuery in Action, 2nd edition
 
subject: Launching firefox and IE from a Java App