Launch a default web browser from my java application

Hello,
I have been trying to launch my default web browser from my java application, but am unable do it. Right now, I am using ---- "Runtime.getRuntime().exec("cmd /c start <url>"); to launch my webbrowser. It launches the browser but displays the command prompt for a second or so, and then replaces my already existing page with the new url.
Is there any way for me to launch the url in a completely new browser each and every time. And I don't want the command prompt to show up for a sec. Please help...!
Thanks in advance.
-BusyBusyBee

If by any chance your application is an Applet, you can use this to open a new browser window:
getAppletContext().showDocument(new URL(theUrl), "_blank");
But, you probably would have specified if that were the case. Oh well. Hope it helps someone!
-sheepy.

Similar Messages

  • How to launch the default web browser from a java app on MAC

    I know, this topic has been brought up over, and over, however I couldn't find info regarding MAC environments. I don't have any former experience with MAC, but now I'm getting desperate for a solution. I need to be able to pop up the default browser showing a certain URL on MAC/OS. Any clue would be appreciated.
    thanks,
    m. berdan

    I wrote libraies that will do this:
    http://ostermiller.org/utils/Browser.html
    I also keep a list of other resources to help you out:
    http://dmoz.org/Bookmarks/D/deadsea/Java_Help/Web_Browser/
    Stephen

  • Open URL in Web Browser from a Java Application

    Hi,
    I have an HTML document that I want to load in a browser window by clicking on a button in my java GUI application.
    Any suggestions?
    Thanks.

    You can use the Process class to start the web browser with the proper command line arguments (depends on the web browser though). Or on windows, you can have your program create a batch file with the code start url (where [url] is your url), and this will open the default web browser when run (again you must run it with a Process).

  • How can I launch a web browser from my Java application?

    I've reed about this at Question of the Week (http://developer.java.sun.com/developer/qow/archive/15/index.html). It doesn't work for me. I'm running win2000 and trying:
    try {
    Runtime.getRuntime().exec("start iexplore http://java.sun.com");
    } catch (Exception e) {
    System.out.println( e.getMessage() );
    I get:
    CreateProcess: start iexplore http://java.sun.com error=2
    What's wrong?

    This function will launch the default browser under Windows.
    public static void displayURL(String url) throws IOException   {
        String cmd = null;
        Process p;
        try  {
            String os = System.getProperty("os.name");     
            if (os != null && os.startsWith("Windows")) {
                if (os.startsWith("Windows 9") || os.startsWith("Windows Me"))  // Windows 9x/Me
                    cmd = "start " + url;
                else // Windows NT/2000/XP
                    cmd = "cmd /c start " + url;
                p = Runtime.getRuntime().exec(cmd);     
        catch(IOException x)        {
            // couldn't exec browser
            System.err.println("Could not invoke browser, command=" + cmd);

  • Attempting to launch a help browser from a java application

    I am currently investigating being able to view help html files through launching a browser from my Java application. I have come across the java.lang.Runtime and java.lang.Process classes which allow me to launch a browser like Netscape or Explorer and bring up a html file to view.
    What I want to do is launch the browser and bring up an html index file as well as the required html help file every time a user would like to use the help for my application.
    Is this possible using the other exec commands. If so, how? Is there somewhere I can find a user guide for Netscape and Explorer commands in order to send additional commands to the browser in order to do this.
    Thanks.

    Good news is it must be possible because VisualAge does it but I don't know how.

  • How do i Hyperlink to a web page from a java application?

    How do i Hyperlink to a web page from a java application using internet explorer as my default web browser?

    It's very simple.You can start any Application with the class Runtime. The command is an array consisting of the path of .exe and the file to be open.
    String [] cmd={path of IE+Filename.exe,"URL of your website"}
    try
    Runtime.getRuntime().exec(cmd);
    catch (Exception e)
    System.err.println(e.toString());
    }

  • Opening a web browser from a Java prog

    I am writing a pseudo-wordprocessor, and would like to be able to set a JMenuItem's action so that when a user clicks it, the system default web browser opens with the web page that I have selected. (e.g. open up a "Help" web page).
    The JavaDoc/tutorial doesn't seem to have anything on running external programs from within a Java program, so does nayone know how this is done?

    If you don't want to go the Java Runtime route and make your program a bit more cross-platform friendly, you could use the JEditorPane to render an html page directly in your application (assuming of course that you're using Swing).

  • Launching TextEdit on a Mac from a Java application

    I am having a problem launching textedit from a Java application. It was working a week ago on a fresh iMac, but since then I have installed Lightroom, Photoshop, the Studio MX suite stuff, and now the textedit program does not start from my Java app. This is the code that I am using in my application to launch textedit:
    String command = "open -e \""+filename.getAbsolutePath()+"\"";
    Runtime rt = Runtime.getRuntime();
    rt.exec(command);I've also tried it this way:
    String command = "open -e \""+filename.getAbsolutePath()+"\"";
    Process child = Runtime.getRuntime ().exec (command);I've printed the command to execute out on the console and it appeared like this:
    open -ef "\Users\user\Desktop\filename.txt"But it doesn't open textedit. The funny thing is, if I copy and paste that open command into the Terminal, it will open the file in TextEdit. Why won't it work in my Java app anymore, but still work through the terminal? I don't get any errors in the console, it just doesn't open TextEdit anymore. Is there a setting somewhere that might have been changed that let me start TextEdit from a Java app. I checked and TextEdit is still my default program for opening text files, which I guess makes since why it works from the Terminal, but I don't get why it doesn't start TextEdit from my Java app.
    Some of this might just be a Mac issue, I'm new to that system. But the code I'm using used to work. I guess maybe I'm looking for another (better) way of opening TextEdit on the Mac from Java.
    I'm using Java 1.5.0_07. Thanks.

    Try specifying an absolute path for open (/usr/bin/open ?).

  • Calling a web service from a Java application

    Does anyone have sample code showing how to call a web service over from a Java application? I'm deploy to HP-UX and seeking out the most standard and reliable approach.
    Thank you in advance.

    Keith,
    Download JWSDP 1.2, look at the tutorial for JAXRPC, especially
    the client portion.

  • Open default browser from a java application

    How is possible to make a java application that open an html file in the default browser ?
    Thankyou
    [email protected]

    You can do that by running the command "start <url>", for example using Runtime.exec().
    Runtime.getRuntime().exec("start http://java.sun.com");Jesper

  • Launching a Browser from a Java Application

    I want to open an HTML page in the "default" browser. I know how to run commands so I could open IE or Netscape but I want to open a browser without having to know what browser they have installed. It would be nice if there is something that isn't platform dependent. Is this possible?

    It would be nice if there is something that isn't platform dependent. So you've seen the java tip
    http://www.javaworld.com/javaworld/javatips/jw-javatip66.html
    I don't think it's that easy to do what you want so that it is portable... sad that the current API doesn't have great support for programs written in other languages than Java.

  • Closing browser from a java application

    I have an applet having a button Save on it. I am calling a javascript function of closing the browser. But if i click it, a built in message comes to confirm the closing of browser having two opitons Yes and No. Is there any possibility that the browser closes without showing this message?

    May this is the wrong forum to post this message. However you could avoid that close-dialog by setting an opener
      function closeWindow() {
        window.opener="x";
        window.close();
      }So you can fake an self-opened window.
    The behaviour depends on used browser. So this should work for IE and Opera but not for Netscape...
    br
    karl

  • Any new ideas for launching web browser from application

    I have searched the forums trying to find a new way of launching a web browser from a java application. The problem I am having is that on Unix and Linux systems, at least the variety I have access to (not quite sure on what that variety those are as they are not my systems or systems I control), the common method of using Runtime.getRuntime().exec(STRING) with either netscape or mozilla does not work. While using the Runtime.exec method is not the same as a console, I did try on these systems "netscape + A_WEB_ADDRESS" (or mozilla) and it did launch the respective browser with the page, so it appears that at least from the console level, those commands are valid.
    All the forums seem to say that the Runtime.exec method is the way to go. All the source code I have found through links from the forum say the same thing. I have voted on this bug:
    http://developer.java.sun.com/developer/bugParade/bugs/4210168.html
    and the feedback there does seem to indicate that there is similar trouble out there. Below is the code I am using. It does work on Win2000,XP, and Mac OSX. The application is not supported on earlier systems, and as it stands it will not work on Win 95,98, nor ME. Only small modification should be needed for work on those OSs, but as I no longer personally use those OSs, I cannot be sure.
    private void openNativeBrowser(String url) {
    // not the browser itself is started, i only call something like
    // start http://www.javasoft.com
    // and then the standardbrowser will be started ...
    StringBuffer call = new StringBuffer();
    System.err.println(System.getProperty("os.name"));
    System.err.println(System.getProperty("user.dir"));
    try {
    // which OS ?
    String operatingSystem = System.getProperty("os.name");
    // how to call the OS
    if (operatingSystem.toLowerCase().indexOf("windows") > -1)
    call.append("cmd /c start ").append(url);
    else
    if (operatingSystem.toLowerCase().indexOf("mac") > -1)
    call.append("open ").append(url + " &");
    else if(operatingSystem.toLowerCase().indexOf("linux") > -1)
    // use Script 'netscape'
    call.append("mozilla ").append(url).append(" &");
    else
    call.append("netscape ").append(url).append(" &");
    System.err.println(call.toString());
    // start it ...
    Runtime.getRuntime().exec(call.toString());
    catch (Exception e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    As I said, if you have a new way to call the broswer that seems to work on either Unix or Linux, please post it, point to it, or explain it.
    Aaron

    there is a shell script on Linux called htmlview that you can launch like this:
    String[] cmd = {"htmlview", "http://java.sun.com"};
    try {
        Runtime.getRuntime().exec(cmd);
    } catch (IOException ioe) {
        // do something
    }which will open the default browser. Don't think this is available on other *NIX though, although the script itself would probably work so you could include it with your app (/usr/bin/htmlview).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to open a web browser from java

    Hi
    Would anybody please help me with this. I need to open a web browser from my java app but I don't know. What method I can use?
    Thanks.
    Hung.

    You can use the Runtime class for this. It can run any command. So, you can run the .exe file of your Web browser.
    The following code will run Internet Explorer (assuming iexplorer.exe is in C:\Program Files\Internet Explorer):
    import java.lang.Runtime;
    public class Explore{
    public static void main(String[] args) {
    try{
    Process p = Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\iexplore");
    }catch (Exception e) {
    System.out.println("Exception: " + e);

  • How to launch a web browser from a MAC java app

    I know, this topic has been brought up over, and over, however I couldn't find info regarding MAC environments. I don't have any former experience with MAC, but now I'm getting desperate for a solution. I need to be able to pop up the default browser showing a certain URL on MAC/OS from a java application. Any clue would be appreciated.
    Thanks a lot,
    michael berdan

    I wrote libraies that will do this:
    http://ostermiller.org/utils/Browser.html
    I also keep a list of other resources to help you out:
    http://dmoz.org/Bookmarks/D/deadsea/Java_Help/Web_Browser/
    Stephen

Maybe you are looking for

  • Blank csv from interactive report

    I have an interactive report that shows the data just fine. but when I choose download and csv, I get a blank file, zero lenght. there is data in the report, but the download shows nothing. has anyone see this before? its just a standard report, noth

  • Allow right-click selection in a JTree

    Hi everybody! How are today? Fine? I hope so. I've got a little question about JTrees: i want to put a right-click popup menu on my JTree, which may not be the same depending on which node of the tree is selected. My problem is that i must do a left

  • HT4623 setting a pass code on the Ipad

    Several weeks ago I updated the software on my ipad2.  After completing, I needed a pass code.  I never set a pass code so therefore I had to restore the ipad.  (one major headache!).  I'd like to update the software, but I do not want to go through

  • Is Captivate 7 backward compatible with Captivate 6?

    We are about to do a lot of work for a client that requires us to procure about 10-12 licenses of Captivate. We already had about 3 Captivate 6 licenses and thought we'd buy the remaining 7-9 licenses of Captivate 6. We're now contemplating purchasin

  • Failed to use EJB's from startup class

    Hi, we use a startup class to set up some base services of our application. The startup class must call some remote methods in a EJB. Unfortunately a CLassCastException is thrown when we try to create the EJB by calling the create method on its home