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.

Similar Messages

  • 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.

  • 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.

  • 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

  • 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);

  • How to launch a browser from a java/MAC application

    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 launch 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).

  • 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).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Control browser properties from a java application while launching a browse

    How to control the properties of a browser when it is launched from a java application?
    I am using the command " Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+url); " to launch the browser. The syntax of "exec" command is "public Process exec(String command,String[] envp) throws IOException". I would like to know whether we can give the arguments in this command to control the browser properties.
    If you know any other option by which we can open a URL in a controlled browser, please share it.
    Thanks in advance :).
    Surekha_Venugopal

    Hi All,
    I have found a solution to control browser parameters from Java applications.
    1. Create an intermediate HTML file at runtime which contains Javascript to launch a browser. Pass the parameters like the URL and browser control parameters to the Javascript of this HTML file.
    2. Open this HTML file and invoke the javascript while loading the file. Javascript will launch the required URL in a controlled browser.
    3. Close the intermediate HTML file.
    Limitation:
    1. There will be a flickering of windows.
    2. Applets will have permission issues with the above solution. For applets a better solution is JSobject. No need of an intermediate file here.
    Hope this will be useful for someone. :-)
    Cheers,
    Surekha_Venugopal

  • 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 ?).

  • Launching a java application from another java application

    Hi,
    I'm facing an interesting challenge :-)
    Inside a Java application, I want to start another java application.
    Possible solutions in my list :
    1. Using jakarta commons launcher.
    2. Runtime.exec (make the code platform dependent).
    3. Starting the main method of the other app by create a new Thread inside the current app
    4. I know people did this by calling an ant target from the java application but I don't have
    any sample code, I appreciate any sample code for it.
    Thanks,
    Ali Salehi

    That is an iteresting challenge :)Don't be mean; he's polite, done some investigation and taken the trouble to be clear. The question, presumably, is "has anyone got a different solution or a preference as to which of these is the best?"
    In which case, my advice would be to say that invoking main in a separate thread is fundamentally different from Runtime.exec() because the former would run in the same JVM. Is this what you want? If one app has the other on its classpath then do they need to be separate apps? Could they be modules of a single app?

  • Launching Java Application From A Java Application

    Hello,
    I am building a compiler and would like to have run feature. The problem is I can not seem to figure out the righ syntax to run and application from my java application.
    Here is the code I am using to run an application:
    public void RunClass()
    try
    Runtime rtr=Runtime.getRuntime();
    Process pr = rtr.exec("java " + CurrentDirectory + FileNoExt);
    String line;
    BufferedReader rerr = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
    if((line = rerr.readLine()) == null) { CompileMessageArea.setText("Program Running\n"); }
    while ((line = rerr.readLine()) != null) { CompileMessageArea.append(line +"\n"); }
    rerr.close();
    catch(Exception re) { re.printStackTrace(); }
    The following is an example of what the above would send to the:
    java c:\MyJava\Programs\test
    If you try to type something like that in a DOS prompt it will not work. You must first change to that directory, but I am hoping there is an easy way to change the syntax. On the other hand if you want to compile a program you can type:
    javac c:\MyJava\Programs\test.java
    and it will work just fine. This is kind of funny and I use this syntax for my compiler in my program. You would think that the same syntax would work the same for both compiling and running but it does not. So, I know that if I just know what the correct syntax that dos would except for running an application it would work.
    So, if you have the answer for me PLEASE LET ME KNOW.
    It is easily testable by keying it into the dos prompt.
    Sincerely,
    Eric Kohr

    If you want to do it that way you need to use the environment parameter of the exec() method. Use it to set your classpath to the directory that's need for the java application you are about to run... for instance.
    String[] env = new String[] {"CLASSPATH=c:\classes"}
    String command = "java somePackage.someProgram";
    Runtime.getRuntime().exec( env, command);Where your program is in the file "c:\classes\somePackage\someProgram"
    your mileage may vary :)
    You can also reflectively load classes into the running VM and invoke their main methods. This give you the ablility to control them a bit more.

  • 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());
    }

  • Running a dos command from a java application

    hello,
    I'm trying to execute a batch file from a java application. I tried with:
    try
    Process proc=Runtime.getRuntime().exec("fop -fo "+iXmlFoFile+" -
    svg "+SvgFileName);
    }catch (IOException e){System.err.println("Error in conversion of
                               the Xml FO file into Svg file: "+e);}
    and with:
    try
    Process proc=Runtime.getRuntime().exec("cmd ./c fop
    -fo "+iXmlFoFile+" -svg "+SvgFileName);
    }catch (IOException e){System.err.println("Error in conversion of
                the Xml FO file into Svg file: "+e);}
    but i have a IOException: CreateProcess: .... error=2
    When I try these line to launch a .exe file it works but not with a .bat file.
    I also tried:
    String execstr = "fop -fo "+iXmlFoFile+" -svg "+SvgFileName;
    String [] commandArray = { execstr };
    try {
    Runtime.getRuntime().exec(commandArray);
    } // end try
    catch ( Exception e ) {
    System.out.println( e.getMessage() );
    e.printStackTrace();
    }// end catch
    but i got the same exception in java.lang.Win32Process.create
    What did i do wrong?

    Your execution string is a bit more that I want to figure out, but here are a couple ideas:
    Is the working directory of any importance? If so you'll need to set that when you do your exec()
    I think I remember reading something about batch files that couldn't be kicked off via this method. Perhaps you need to execute the string "start mybatchfile.bat". Seems like you need to do something like that to get a command interpreter to run your batch file.

Maybe you are looking for

  • P35 Neo2 - OS died, need help restoring RAID after re-install of XP

    I have a P35 Neo2 with on-board Intel RAID.  I need a bit of help getting a two drive RAID going again after reinstalling XP. Here's my situation: Same hardware, MB, etc. I originally set up the system with a 20gb IDE and two 320gb SATA drives. I put

  • How do I put a fillable form on our website so people can fill it out and send back to me

    How do I put a fillable form on our website so people can fill it out and get it back to me.

  • Film download is stuck

    I have tried to download a film and the download is stuck, it keeps going back to the 890k download and restarting. I cannot delete the download or try to download another version. Any ideas?

  • Afterpform - not returning all info

    I am 'printing/displaying' the parameter form on the last page of the report via the trailer section. I have sucessfully added some of the parameters to the last page display the title and &parameter such as Store: &store However I have a parameter t

  • Value formatting on chart axis in WAD

    Hi experts, In WAD charts, I use an ordinary line chart. Is there a way to format the value on the axis so that it becomes thousand separated? I.e. Instead of a value on the axis of 80000000, we would prefer to have 80 000 000. BR, Niclas