wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes calling browser from Standalone Java application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "calling browser from Standalone Java application" Watch "calling browser from Standalone Java application" New topic
Author

calling browser from Standalone Java application

mohana konakanchi
Ranch Hand

Joined: May 16, 2001
Posts: 67
Hi
Does any body knows how to call or instantiate default browser and show some html page from standalone application(Not from applet)?
any example is help full
Mohana
Thomas Suer
Ranch Hand

Joined: Sep 03, 2001
Posts: 50
What I know:
in the java.lang.Runtime class there is a method called 'exec()'. With this method you can run any program. All you have to do is pass the browser's 'exe'-file name and its parameters to load the desired html-file.
What I don't know:
how to get the default browser.
Good luck!
Tom
[This message has been edited by Thomas Suer (edited October 30, 2001).]
george justin
Greenhorn

Joined: Jul 31, 2001
Posts: 25
Hi
You can try this out
String[] param = {"c:\\program files\\plus!\\microsoftinternet\\iexplore.exe","www.javaranch.com"};
Runtime r = Runtime.getRuntime();
Process p = null;
try
{
p = r.exec(param);
}
catch(Exception e)
{
System.out.println("Error executing " + e);
}
Bye
George Justin
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
if you need the browser to render some specific html page, than use JEditorPane (or was it JTextPane?) to do that. theres lots of documentation about this with sample code (java.sun.com).
chantal
Jeremy Hooie
Ranch Hand

Joined: Aug 22, 2001
Posts: 38
The easiest way of doing this to use the Windows start command.

Since HTML files are bound to the default browser, you don't even have to specify the browser.

You will need to implement your own start script on other platforms.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

What version of windows does "start" work on? It doesn't work on my WinNT box here at work... The way I've always seen it done is either the program assumes you have a certain browser installed in a certain place, or when you install or the first time you click on a button that would launch the browser, you have to specify which browser you want to run ( usually the program opens up a file dialog to get this info... )

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Bigglesworth Naruki
Greenhorn

Joined: Nov 05, 2001
Posts: 14
Really? I was under the impression that START works on all 32-bit Windows platforms. Try it from a DOS prompt. Maybe your path is screwed up...
Originally posted by Nathan Pruett:
What version of windows does "start" work on? It doesn't work on my WinNT box here at work... The way I've always seen it done is either the program assumes you have a certain browser installed in a certain place, or when you install or the first time you click on a button that would launch the browser, you have to specify which browser you want to run ( usually the program opens up a file dialog to get this info... )

-Nate

mohana konakanchi
Ranch Hand

Joined: May 16, 2001
Posts: 67
HI,
Thanks a lot for your replies.
we can do use
Runtime.getRuntime().exec("start iexplore [webaddress or file]");
or
Runtime.getRuntime().exec("http://www.webaddress.com");
But, it's depends on type of windows Operating system we use.
If I want to know path of default browser exe file.
Is there any mechanisam to get it irrespective of type of windows
platform?
If that can be possible, we can make standalone application
atleast independent of different windows platforms.
thanks in advance,
Mohana
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Jeremy ( & Bigglesworth ),
Sorry... "start" launches a new command-prompt window at the command prompt... I was trying it from the "Run..." option in the start menu... I guess you learn something new every day...

Mohana,
There is no way to get the path of the default browser from the OS... remember, Java is a platform independent language, and most OS's don't support the "default" browser idea. What if, instead of running in any version of windows, a user wanted to run your program under Linux? The best thing to do is probably ask the user when installing, or when trying to access the browser for the first time, and save that path somewhere so you can access it later.

-Nate
bkrasnof
Greenhorn

Joined: Nov 09, 2001
Posts: 2
check out (the first 2 links expand on work that the javaworld article started):
http://www.stanford.edu/~ejalbert/software/BrowserLauncher/
and
http://ostermiller.org/utils/Browser.html
and
http://www.javaworld.com/javaworld/javatips/jw-javatip66.html
mohana konakanchi
Ranch Hand

Joined: May 16, 2001
Posts: 67
Hi Nathan
Getting browser path while stalling may not viable solution.
No user like to find and give paths to something while installing.(unless user is a developer also ;-)

The URL s given by bkrasnof is very good.
They have given few more options for calling default browser.
There is a free software which takes case of platform and other issues itself.
I tested in Windows NT. It's is working fine.
Java tips of java world has given some code for two platforms. it may not be useful since, it's ristricted platform.
But useful for those platforms since code is small.
greate feedbacks, more possiblities, thanks every body.
Mohana
mohana konakanchi
Ranch Hand

Joined: May 16, 2001
Posts: 67
HI
I used Runtime class to get default browser. it's giving exception.(Windows NT platform)
I need to use local address to get html page
String strWebAddress = "E:/JRE1.3/myfolder/myinfo/001+020+009.html";
Runtime.getRuntime().exec("start iexplore "+strWebAddress);
java.io.IOException: CreateProcess: start iexplore E:/JRE1.3/myfolder/myinfo/001+020+009.html error=2
If i cut and paste same at command prompt it's works some times and does not work sometimes.( no idea why and when it does not work)
What could be the problem? What is this error=2 means?
Thanks in advance
Mohana
mohana konakanchi
Ranch Hand

Joined: May 16, 2001
Posts: 67

Could some body give some reply on my previous posting.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling browser from Standalone Java application