Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Launching firefox and IE from a Java App

 
Dar Var
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic