Launching various external applications from a java application

I have several java.io.File objects displayed in my swing application. When the user double clicks any of these objects, I want to launch the external application associated with the file type.
For eg. if the user double clicks on "one.pdf", I want to launch Adobe Acrobat to view that file. I dont want to hard code application and file extension associations, rather I want to launch whatever it is that the underlying OS would launch given a double click on a certain file type.
Anshuman Taneja.

Let me answer my own question. Did not know the solution would be this direct. On the flip side, this is not a cross platform solution, and perhaps, there isnt any cross platform solution.
(in the code below, file is a java.io.File object.)
// if the file is an "exe", then it is launched like this
if(file.getName().indexOf(".exe") > 0 )
Runtime.getRuntime().exec("rundll32" + " " +
"url.dll,FileProtocolHandler" + " " + file.getName());
// for files which are not applications themselves,
// this will launch the application windows would've launched to open the file
else
Runtime.getRuntime().exec(new String[]
{"rundll32", "url.dll,FileProtocolHandler",
"file:///" + file.getAbsoluteFile()});

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.

  • How can I create a shortcut to launch an external application?

    Hello, I'm developing app in Swing where I want to create a shortcut for any external application, I'm able to get the .exe path, and an icon path (in .png format), is there a way to create a "shortcut" or button and assign the icon and the .exe path to run it? This is what I have to get the .exe path:
    Process p = Runtime.getRuntime().exec("\"" + jTextField2.getText() + "\"");
    Where jTextField takes the value from a JFileChooser value, doing the same for the icon, then I could do this for a button to assign the icon:
    ImageIcon img1 = new ImageIcon("C:\\image.png");
    jButton7.setSize(64, 64);
    jButton7.setIcon(img1);
    But I havent' found any way to make the button (or any kind of shortcut) to execute the program, I could go and create a method to do it on click or ActionPerformed, but the idea is to do all this when I finish the create the shortcut, I hope you can understand me, I'm kinda confused, so far, I can launch the app but I want to create a new button/shortcut everytime I need to add an external app, thanks in advanced!!!

    user3538005 wrote:
    Hello, I'm developing app in Swing where I want to create a shortcut for any external application,.. For what end purpose? If it is to show documents in the default consumer for that document type (e.g. a .doc might be MS Word), then look to the <tt>java.awt.Desktop</tt> class.
    ..I'm able to get the .exe path, and an icon path (in .png format), is there a way to create a "shortcut" or button and assign the icon and the .exe path to run it? This is what I have to get the .exe path:You do realize that is disgustingly Windows specific, right? What about users of Mac and *nix?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Sending POSIX signal to an external subprocess from a java program

    I'm programing in forte for java under linux-mandrake, I've execute an external subprocess with the runtime and Process clases, I need to send the 2� POSIX signal to this external subprocess, I mean de SIGINT signal, I know that you can send a signal from a shell just doing:
    Kill -2 pid // the SIGINT signal is the 2 POSIX signal
    I know that there is another system-call like : kill(int signal, int pid) that any one can send from a c program.
    Althought I don't know how can I get the pid of a suprocess, because I Know that there is the systemcall in c like:
    int getpid() wich gives the pid of the current process, but I need to have the pid of a subprocess not the current one.
    The thing is that I do not know how can I do it from a java program, I mean that to send a signal to a subprocess it will work using system-calls, but I do not know if I can insert system call in a java program, I've been thinking about doing it using a linux script like:
    #!bin/bash
    $a = pidof /home/maude-linux/bin/maude.linux
    # this is the path of the process wich is running
    kill -2 a$
    and the run this script from a java program doing an exec(sh script.bin)
    but by the moment I must be doing something wrong in the script because I find mistake in it, it gives me mistake in the assign sentence , I mean:
    $a = pidof /home/maude-linux/bin/maude.linux
    # this is the path of the process wich is running
    I'm not used to program shell scripts, perhaps I'm doing something wrong, is there something wrong in this sentence?.
    I would aprecciate some help about this, or if somebody have some idea how to do it in java, I repeat I need to send a signal to a external subprocess wich is launched from a java program by the process and runtime clases, and I need to send a SIGINT signal to the subprocess, I hope that some body can give some suggestion or some code explaining the situation

    Are the portions of bash-code verbatim in your post?
    When yes, they look suspicious!
    Instead of
    #!bin/bash
    #!/bin/bash
    would be better.
    $a = pidof /home/maude-linux/bin/maude.linux
    does not look good either.
    If you have command "pidof" telling the pid based on the path name of the executable passed to it as its argument, you can have the output of this program in a shell script like this:
    a=$( pidof /home/maude-linux/bin/maude.linux )
    Then through $a you will refer to the value of the variable "a":
    kill -SIGINT $a
    A pidof script could look like this (apart from error handling):
    ps -ef|awk '{if (NF>=8 && $8=="'"$1"'") print $2;}'
    This works for me; your mileage may vary.

  • 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 can I launch an external app from a keynote presentation?

    I'm trying to launch a Prezi presentation ("Prezi.app") from a keynote presentation, but don't know how to do it.
    Links in keynote can only refer to websites or slides within the presentation, but not to start another App, like in - I hate to say it - Powerpoint.
    Any ideas?
    Thanks
    Juergen

    Keynote is specifically prevented from opening applications.
    In Keynote 09 (the previous version), hyperlinks can:
    Jump to a slide in the same presentation
    Open a webpage in the computer’s default web browser
    Open another Keynote document
    Open an email message
    Exit the slideshow
    in Keynote 6 (the latest version) hyperlinks can:
    Jump to a Slide in the same presentation
    Web page
    Mail opens a pre-addressed email message
    Exit the presentation

  • How to launch a new JVM from a java class?

    I want to update a runing java applicaton. Before updating it, I have to shut down this application and open a new JVM (launch another java class with main method inside another JVM). Then update this application. After updating, restart this application. How to do it?? Thanks. Gary

    Hi!
    I'm using an applet to upload a library in the ext directory and then opening another applet that uses that library...
    If I manually upload the library the second applet works
    but if I try to load it at runtime with the first applet the file is saved correctly but the second applet doesn,t work :((
    the second applet works only if I close the browser and open it again...:((
    I need to reaload the JVM at runtime or maybe opening a new one...
    can anyone help me?
    please reply me if you found anything similar,
    ciao!
    fabibu

  • Launching an external file from jsfl script

    I've written a jsfl script which exports the frames of a
    Flash movie as pngs. I've also written a Photoshop .jsx script
    which takes the pngs and processes them. I was wondering if there
    was a command available in jsfl that could launch the .jsx file
    once the Flash process was finished?
    Cheers guys!

    mburgos,
    Take a look at this doc for starters:
    http://download-east.oracle.com/docs/cd/B31036_01/doc/appdev.22/b28839/up_dn_files.htm
    Unless the end users have mapped drives to those documents, that's not going to work. Is this path just a pointer to the file on the server (if so, why not a BFILE)?
    chet

  • Launching external applications from web start

    Hi!
    I am currently working on a management system and I need to launch other management systems from my Java Web Start application. The other systems are either based on web applications (URLs), telnet - needs to set up a telnet session, or running shell scripts or batch files.
    URLs are ok. I am using Desktop.browse in Java 1.6 or I can use BasicService.showDocument in javax.jnlp API.
    My application may run on both windows and linux (ie its launched from the browser). It interacts with a java app on a linux server over RMI.
    How can I lauch a telnet session from my client app?
    Do I have to include apache commons.net and create a telnet module in my app or can i lauch c:\windows\system32\telnet.exe in windows (if my app is lauched on win) and /usr/kerberos/bin/telnet (if my app is lauched in Linux)?
    How can I launch an external .exe application in window and how can I launch any shell script or program in Linux?
    (same as how do i lauch telnet)
    As long as the user is prompted I can see no risk of denying these kind of things so I hope and think that this should be possible!
    PS. I have managed to do it by using Runtime.exec() when running as a non JWS application, but I cannot do it when running as JWS:
    java.security.AccessControlException: access denied (java.io.FilePermission <<ALL FILES>> execute)I dont want to sign the application either. The reason for choosing webstart was to not have to renew certificates at our customers.
    Please help.
    Thanks for taking interest and reading this.. and I hope that someone has some helpful answers for me :)
    Edited by: Tomas_Andersen on Feb 5, 2008 6:34 AM

    Do you know how to launch Java applications (not applets) from web pages ? Thank you.
    you can setoff a java servlet from a webpage.Is that what you are talking about ??? activeateing a server side app ????

  • Calling external programs from within a Tomcat application

    I've got a fairly complex existing Tomcat application (which is packaged and built as a .war file) which I'm trying to edit so that it calls a Perl script part way through the processing, which will generate an XML file used later on. I think I've worked out how to call external scripts from within Java, but at the moment when I try and access the application via Tomcat the application either hangs or bails out (I don't know which, as the log files unhelpfully don't give any error messages).
    The code which is causing the problem looks like this:
    System.err.println("Calling runtime...");
    Runtime runtime = Runtime.getRuntime();
    System.err.println("Executing process...");
    Process process = runtime.exec("/path/to/ysearch.pl 'News' '\"search query\"' 'file");
    System.err.println("Waiting for process...");
    int exitVal = process.waitFor();
    System.out.println("Exited with error code: " + exitVal);The code gets as far as "Executing process..", beyond that there is nothing in the log file so I presume the runtime.exec() call is where the problem is. I'm not interested in reading the output from the script (there shouldn't be any), so that's not an issue, and the permissions on it allow anyone to read or execute ysearch.pl so I don't think there's a problem in that area.
    Does anyone have any suggestions which I could try to get this to work? I've only been using Tomcat for a week (I'm picking up on someone else's code) so I might have made a beginner's mistake. I'm using Tomcat 5 on Fedora Core 7, and Java 1.5.0_01 (I can't easily change any of those).

    I'm not sure, but I thing that overhead caused by calling du cannot be big enough to matter even on older machines.
    But, when calling du from Perl script you are also invoking shell, and this can be a little bit more 'heavy'.

  • Can I send keyboard/mouse commands from a VI to an external application?

    I am launching an external application (BeamScan.exe by Photon) in Windows 95 from a LabVIEW 5.1 VI using Exec. I want to be able to configure the external application from its own menu bar, sending key commands or mouse clicks from the VI. I need to do it this way because the external application has only limited ActiveX capabilities which do not include the menu options I want to control.
    Is it possible to send keystrokes or mouse clicks through Windows 95 to the other application?

    Steve_rvk wrote:
    > I am launching an external application (BeamScan.exe by Photon) in
    > Windows 95 from a LabVIEW 5.1 VI using Exec. I want to be able to
    > configure the external application from its own menu bar, sending key
    > commands or mouse clicks from the VI. I need to do it this way
    > because the external application has only limited ActiveX capabilities
    > which do not include the menu options I want to control.
    >
    > Is it possible to send keystrokes or mouse clicks through Windows 95
    > to the other application?
    Download "Simulate Click" and "Simulate Key Event" from my web site.
    It's on G Toolbox page.
    George Zou
    http://gtoolbox.yeah.net
    http://go5.163.com/~georgezou

  • Launching client side application

    Is there a way to launch an external application on a clients machine from an applet in a browser? I've been searching all over the internet with no luck...any help would be greatly appreciated

    I also say one more thing. A trusted applet has the ability to execute a command. You can find more info about trusted applications from
    http://java.sun.com/docs/books/tutorial/jar/sign/intro.html

  • Launching external link from E-Business suite

    Hi,
    I have a requirement to launch an external application from Oracle Application.
    I have a responsibility say 'Launch External App Responsibility' .
    When i click on that, it should launch my application (assume i have the URL of my external Application)
    Any help will be appreciated.
    Thanks in advance.

    Hi,
    Hi,
    Please see these links/threads.
    Note: 332500.1 - How To Call An HTML Webpage From 11i Navigator Menu
    Note: 883404.1 - How To Access External Url When Using SSWA PLSQL Function
    Registering my website to e-Business Suite Apps
    Re: Registering my website to e-Business Suite Apps
    Thanks,
    Hussein

  • Base Tables that store external application information

    I have created several external applications. I would like to know where are these applications stored ie. in which tables under what user . I want to get the corresponding external application id to the external application name , so that I can pass it to one of my functions to launch the external application.

    I think you want wwsso_application_info_t and
    wwsso_appuser_info_t owned by portal30_sso
    null

  • Launch 2 batchs from a java program

    Hi,
    My pb is the following one:
    I launch a batch file from my java program. This batch launch another program. But it seems that the java program take back the hand and stop the execution of the last program.
    How can I make the java program waiting?
    Thanks in advance

    Thanks Felipe.
    I've tried your suggestion and I've discerned the real bug. In fact, it's the program that I launch through the batch file which don't perform.
    Here is my batch file:
    C:\program files\pvcs\vm\win32\bin\pcli.exe run -sC:\program files\pvcs\vm\win32\bin\noexiste.pcli %1 %2 %3
    In fact, it has to launch pcli.exe, which has to launch a script.
    The pb is that when I run the batch file manually, it works. So, it comes from the java prg. Here is the command lines in my program java:
    try
    String cmd = "C:/Progra~1/Pvcs/Vm/Win32/Bin/transfert.bat";
    String[] cmdArray = { cmd, Str_LabelModule, Str_FichierSauvegarde, Str_AccesArchive };
    Prc_MyProcess = Rt_MyRuntime.exec(cmd);
    System.setProperty("ATTENTE", "VRAI");
    while(!b_stop)
    if(!System.getProperty("ATTENTE").equals("VRAI"))
         b_stop = true;
    else
         Thread.sleep(1000);
    }catch (Exception exc) {exc.printStackTrace();}
    I tried this program with a simple batch (echo %1 %2 %3 > c\toto.txt) and it works.
    Have you an explanation for this?

Maybe you are looking for

  • Communication Problem between Listener and OEM

    Dear all, I had my OEM running and communicating with the database without any problem until I had a problem with other client and kill some OEM and Listener process, now it's not communicating with the listener. I restarted my PC and tried to start

  • Gif's in mac mail

    I recently received an email that contained an animated GIF file that I thought was pretty cool and would like to share. However, whether I forward the email or save the gif to desktop and attach it to a new email, it doesn't work. I believe it has s

  • How do I recover an episode of a tv show if I accidently deleted it from itunes in the cloud?

    I recently tried to free up space on my pc, by going into iTunes and deleting episodes of a tv show I watch often & repeatedly, but knowing that I usually download it when needed to give my iPhone/ipad space the rest of the time. However, somehow I f

  • ITunes Match no longer working

    Wow. I don't even know where to start with this. But here's the problems I am having- I am hoping that someone can steer me in the right direction. I've been trying for a few weeks to get this straightened out and am still quite stuck. I had iTunes m

  • MacBook Pro freezes when it connects to internet

    All of a sudden my computer freezes (spinning wheel) anytime I connect it to the internet. Does anyone know what I can do to fix this? I have rebooted several times and have enough memory. What could it be? Thanks in advance