Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4210168
Votes 148
Synopsis Add a system method for launching the user's default browser
Category java:classes_lang
Reported Against 1.4.1 , 1.1.7a
Release Fixed
State 11-Closed, duplicate of 6255196, request for enhancement
Priority: 4-Low
Related Bugs 6255196 , 4906974
Submit Date 09-FEB-1999
Description


I subscribe to several Java development mailing lists for various platforms.
One question that comes up alot is how to best use Runtime.exec() to pass a URL
to  the Netscape browser. Now, on UNIX and Windows platforms, one can pass in a 
String containing the URL as one of the parameters, or just pass in the URL as 
part of a command-line flag( i.e.: 'Runtime.exec(" customer  -remote  http://my.url.com")');
however, on Macintosh, command-line flags are not 
supported. Apple's Java porting team has worked around this issue by having 
their implementation of the runtime parse the parameters, and if the parameter 
looks like a URL, they send a "gurl" AppleEvent to the browser, which tells it 
to load the URL. 

Since this seems to be the most common use of Runtime.exec(), it would be a 
nice feature to have an exec method which accepts a URL  customer  (this would make 
life easier for the Apple folks, at least - they could just have their 
implementation send the "gurl" event when Runtime.exec() is called with a URL  customer  as a 
parameter). In this way, developers could simply pass in a URL  customer  (which 
may have been constructed for some other reason in their application) to invoke 
the browser with. 

This way, the platform-dependent implementation could just
get the URL string from the URL  customer  and pass it appropriately
to the browser.
(Review ID: 43562)
======================================================================
Posted Date : 2005-08-05 13:25:06.0
Work Around
N/A
Evaluation
There's an interesting idea here if you think about it as something like

    System.launchBrowser(URL what);

rather than as a warped version of Runtime.exec.  There is a real need for
programs to be able to find the user's default browser (if one exists) and
cause a given URL to be displayed in it.  We should see how much demand there
is for this and proceed accordingly.

--   xxxxx@xxxxx   1999/2/19

This feature should be considered for Tiger.

--   xxxxx@xxxxx   2002-03-22

The functionality proposed by this RFE has been implemented as a subset
of RFE 6255196. See the description of that RFE for API details.
Posted Date : 2005-08-24 17:02:21.0
Comments
  
  Include a link with my name & email   

Submitted On 07-MAY-1999
riddle
I now NEED this System.launchBrowser(URL).
I came here looking for it or the workaround.
The application can't pre-know what the progname of any possible default
browser on the every user-system
so it needs a generic way to launch URL viewing.


Submitted On 28-MAR-2000
hersker
FYI, while we're waiting for Sun to implement 
System.launchBrowser(), here's how to run the default 
browser on Win9x/NT. Call Runtime.exec() with this string:

rundll32 url.dll,FileProtocolHandler your-URL-here



Submitted On 11-APR-2000
jvmyers
In my application I use rundll32 exactly as shown, but I have a problem
with running it with Netscape 4.7 on my laptop.  When Netscape is started,
it brings up a Profile Manager dialog to choose the profile name.  This
causes an error message "Unable to open" the url.  Once I choose a profile
and start Netscape, it displays the url but I have to cancel the error message.

A second problem exists if Netscape is already open.  If my application issues
the rundll32, the browser never updates the page with my url.  This also only
occurs on my laptop with the profile manager.

Does anyone know of a workaround for these problems? 


Submitted On 15-NOV-2000
julian.bunn
An even simpler way to launch the default browser:

thisRun.exec("start http://.... ");

where http://.... is the required URL.



Submitted On 01-DEC-2000
ejalbert
I've actually written a class that does this, 
cross-platform (well, Mac/Windows/Unix), without using 
JNI.  See 
<http://www.stanford.edu/~ejalbert/software/BrowserLa
uncher/> to download it.


Submitted On 11-MAR-2002
victorF
Found there is no a robust way in a java app to launch a 
brand new netscape browser on unix. the runtime.exec() way
to launch works on windows but not unix. 


Submitted On 02-MAY-2002
thedeadsea
Apple - MRJFileUtils.openURL() not implemented in Mac OS X.
http://developer.apple.com/techpubs/macosx/ReleaseNotes/JavaGMWebReleaseNotes.html#MRJToolkit

Apple - How one would open a URL in a web browser on a
Macintosh.
http://developer.apple.com/qa/java/java12.html

Browser Utility - Class to launch a URL in a web browser in
a platform independent manner. Includes an optional swing
GUI allowing user customization. [Open Source - GPL]
http://ostermiller.org/utils/Browser.html

BrowserLauncher - Open the system web browser with
particular attention paid to various Macintosh systems.
(Freeware)
http://browserlauncher.sourceforge.net/

Java World - With a little platform-specific Java code, you
can easily use your system's default browser to display any
URL in Windows or Unix.
http://www.javaworld.com/javaworld/javatips/jw-javatip66.html

JConfig - Class Libraries that allow a URL to be launched in
a browser on Windows, Unix, or Macintosh. [Commercial] 
http://www.tolstoy.com/samizdat/jconfig.html


Submitted On 05-MAR-2003
paultr
Since my reason for searching the bug database today is 
because, on Solaris 8, I cannot get the "netscape -
remote 'openFile(xxxx)' to work in Runtime.exec(), I'll vote 
early and often for this method.  More and more applications 
are going to html output, and spawning Netscape, Explorer, or 
whatever the default browser is would be much preferrable to 
using NetClue or some other limited, homegrown Java 
browser.  Why not take advantage of the industry's best 
products?


Submitted On 01-SEP-2003
pilaftank
Microsoft claims that C# applications can be written in much
less time with half the lines of code as Java applications.
 If Java is to win the war, it must get better at doing the
higher-level stuff.  A universal browser launch feature is a
great example.  Besides, this feature is needed for true
platform independence.


Submitted On 02-SEP-2003
asjf
this would be a very welcome addition - in the forums its 
often requested:

http://search.java.sun.com/search/java/index.jsp?
col=javaforums&qp=&qt=launch+browser


Submitted On 11-SEP-2003
BacMan
I am currently using http://ostermiller.org/utils/Browser.html, 
but am unsatisfied.  It doesn't work with file protocols and 
pops up a message when for whatever reason it can't open 
the URL.  It makes my Swing application look unprofessional.  
I sincerely hope Sun can come up with a solution ... soon.


Submitted On 16-SEP-2003
irun5k
This is long overdue.  I'll be very concerned about the
state of things if we don't see this in Tiger.

Almost every desktop app known to man has at least a "MyApp
on the Web" item under the help menu.                      
                   Every platform has a web browser, so this
should be easily implemented as a basic function call. 
Don't let the number of votes fool you on this one.  This
question gets asked ALL THE TIME.


Submitted On 20-OCT-2003
TWCox
Currently using a modified version of the BrowserControl 
workaround posted at JavaWorld ( 
http://www.javaworld.com/javaworld/javatips/jw-
javatip66.html )

Of course, BrowserControl fails more often than not on Unix, 
and because Runtime.exec() tampers with the quoting of 
arguments, it also fails on Windows 2000.

Please fix this...


Submitted On 06-FEB-2004
jreichen
I need a function to launch any document in its 
associated application.


Submitted On 12-MAR-2004
Peter_Schaefer
System.launchBrowser(URL) would be super-cool.

While this is easy to do on Windows, I have not  yet found a
reliable method on Linux. Which is, by the way, not  Sun's
fault...


Submitted On 23-MAR-2004
irun5k
65 votes and requested since 1.1 and no action?  man, come
on Sun.  This is a no-brainer.  Why wasn't this added to 1.5?


Submitted On 10-MAY-2004
MihalyBak
Runtime.getRuntime().exec("explorer.exe \""+ path 
+ "\"");  

works under Windows... note that it uses explorer.exe 
not IExplorer.exe so it should open the default 
webbrowser I dont use Netscape as default so I 
haven't tested it but it should work


Submitted On 01-JUN-2004
Lluis_Turro
launchBrowser() method will also solve PDFs problem. Right now, in Linux, you need to create KDE dependencies, afaik, in order to launch default PDF application. That is, calling "kfmclient exec file.pdf"


Submitted On 29-JUL-2004
wgreene9617
It's been 5 years since this was submitted and Sun still doesn't get this "internet" thing.  Sheesh.

I've been attempting to use BrowserLauncher  from http://browserlauncher.sourceforge.net/ but for some reason on Solaris9 using JDK 1.4.1 I can get it to launch netscape7 and go to the desired URL but if netscape is already open it fails and tries to launch a new browser.  Ummm... less than optimal.

I've not tired Windows yet.  Most of my customers will be Solaris.


Submitted On 23-SEP-2004
TE_Schmitz
I have googled around to find a solution for something as simple as firing up the default browser on Linux. No success. JDIC expects Mozilla, BrowserLauncher Netscape. Why isn't this part of the Java API?


Submitted On 15-OCT-2004
neil_laurance
Assuming this method ever makes it into the product, could we have the following parameters:

- The base URL string
- A collection of request parameters
- A width and height for the browser window
- A boolean (or some other method) to identify the request to be a GET or POST method

Here's hoping ;-)


Submitted On 17-DEC-2004
renodream13
More problem are encountred when you have to implement this for Windows 9,2000,NT, XP and also on UNiX.
System.launchBrowser(URL) will be the best solution


Submitted On 23-FEB-2005
don_seiler
Casting my vote for this.


Submitted On 23-FEB-2005
don_seiler
(offtopic) at _LEAST_ have JEditorPane properly interpret standard XHTML.


Submitted On 03-MAR-2005
primet21
vote++


Submitted On 12-MAR-2005
NiLaY.GoYaL
URGENT!!!
atleast a good workaround should be mentioned while the System.launchBrowser(URL); comes into the picture.


Submitted On 20-MAY-2005
rcengels
see the JDIC project on java.net


Submitted On 23-JUN-2005
derelict.pt
I subscribe to the need to find an easy way to launch a browser without JWS or JNLP


Submitted On 11-JUL-2005
HansBickel
The lack of a System.launchBrowser(URL) method transforms "Write once - run anywhere" to "Write a thousand times - maybe never run anywhere"...
...what an enormous vaste of time and braincycles.


Submitted On 20-JUL-2005
pilaftank
Until this feature is added into Java, here's a fairly simple cross-platform workaround.

Bare Bones Browser Launch:
   http://www.centerkey.com/java/browser


Submitted On 20-JUL-2005
gtorrence
I have had luch with this class. It's simple enough, and modestly extensible:

import java.io.IOException;

public class BrowserLauncher
{
	/**
	 * Launches the user's browser with the specified HTTP URL.
	 *
	 * This method is designed only to work under windows or unix.
	 * For windows, the user must have url.dll set up properly.
	 * For unix, the user must have firefox, netscape, or mozilla in their path.
	 * 
	 * This has been tested under Win NT, 2000, and XP. It has also been tested
	 * under Solaris 7, 8, 9 and Redhat 7, 8, 9, EL3, and Fedora core 2.
	 *
	 * @param url The web page to launch in the format "http://foo.bar.com"
	 *
	 * @throws IOException thrown if no browser is sucessfully launched.
	 */
    public static void openURL(String url) throws IOException
    {
	    int i, j;
	    String[] parameters;

	    // keep track of whether an exec call has succeeded
	    boolean success = false;

	    // get the list of browsers to try
	    String[][] browsers = getBrowsers();

	    for (i=0; i<browsers.length; i++)
	    {
		    try
		    {
			    // Construct the parameter array for the exec call.
			    // It will be the current browser array, plus the url.
			    parameters = new String[browsers[i].length + 1];
			    for (j = 0; j<browsers[i].length; j++)
			        parameters[j] = browsers[i][j];
			    parameters[browsers[i].length] = url;

			    // Try to launch the browser
				Runtime.getRuntime().exec(parameters);

			    // If the exec call fails, it throws IOException and we won't get to here.
			    success = true;
			    break;
		    }
		    catch (IOException e)
		    {
		    }
        }

	    // If we did not launch anything, throw an IOException. Doing so preserves the legacy interface to this method.
	    if (!success)
		    throw new IOException("Failed to locate browser executable");
    }

	protected static String[][] getBrowsers()
	{
		String osName = System.getProperty("os.name").toLowerCase();

		if (osName.startsWith("win"))
		{
			return windowsBrowsers;
		}
		else
		{
			return unixBrowsers;
		}
	}

	
	// Windows always works with just one string to try. Rundll32 will do all the work for us.
	// We can't have a list to try, because the exec call will always create a process, even
	// if something went wrong. So unlink unix, we can't detect failutre.
	protected final static String[][] windowsBrowsers = new String[][] {
		new String[] { "rundll32.exe", "url.dll,FileProtocolHandler" }
	};

	// Here is a list of browsers to try. The exec call will fail to create a process if
	// for the items in this list that aren't in the user's path. In that case, we'll move
	// on and try the next one in the list.
	protected final static String[][] unixBrowsers = new String[][] {
		new String[] { "firefox"  },
		new String[] { "mozilla"  },
		new String[] { "netscape" }
	};
}


Submitted On 08-AUG-2005
The easiest way to open files on a windows environment higher then W98 is:

java.lang.Runtime.getRuntime().exec(new String[] {"cmd.exe", "/c", filename});

Now i have to find a solution for the apple....


Submitted On 15-AUG-2005
mrpeets
PLEASE ADD TO MUSTANG!!!
Adding a vote to this one. Extremely weird that this one hasn't been added.


Submitted On 01-SEP-2005
kuroyume0161
My problem is MacOSX!  So much for limited workarounds.  The original JavaWorld code works on Windows, but not MacOS!!!

For a programming language practically living off of URLs, internet, and browsers, the lack of embedded functionality is sad.  You want to beat MS and C#, you'd better make:

runHTTP(URL)
!!!!!

So this is the best I can get for my search - invent a solution yourself and, by the way, 'good luck, suckerrrrrrrr'.


Submitted On 01-DEC-2005
ninosd
I would add to this to have a pointer returned to the currently opened browser so we can close it later. So besides having a System.launchBrowser(URL) or the System.exec() flavor of taking a URL, have these return a pointer to the browser opened and to have a System.closeBrowser(objBrowser);


Submitted On 15-DEC-2005
Jason-Mehrens
See RFE 6345777 and add your comments or vote before they freeze this API.  The return type of methods provided by the desktop API should not be declared as void.


Submitted On 04-AUG-2006
taijian
vote++


Submitted On 23-AUG-2006
TimGraf
vote++


Submitted On 23-AUG-2006
TimGraf
vote++



PLEASE NOTE: JDK6 is formerly known as Project Mustang