How to launch an application from java?

Hi,
Would anybody please help me this. I need to launch a new desktop application from my java app but I don't know how. For example, when user clicks on a "Edit" button from my java app, my app needs to launch NOTEPAD.EXE to allow user starts editing.
Thanks a lot.
Hung.

try something like this for your button's action method:
        String[] cmd = {"notepad"};
Runtime rt = Runtime.getRuntime();
        try {
            Process pro = rt.exec(cmd);
            pro.waitFor();  // wait until it's done executing
            System.out.println("Process exit code is: " + pro.exitValue());
        }catch(IOException ioe) {
            System.err.println("IOException -> " + ioe);
        } catch(InterruptedException ie){
            System.err.println("InterruptedException: " + ie);
        }

Similar Messages

  • How to launch an app from Java in Mac OSX?

    I would like to launch another application from my Java code which will run on OS X. Doesn anyone know how to do this? I think it involves the "Runtime.getRuntime.exec()" method, but I'm not sure how to tell it which application to launch.
    Thanks

    I dont know about OSX but i can give you a generalized
    solution. In all OS's there will be a way to get to
    command prompt. It is not really true: MacOS is one noticeable exception! Version 9, like every previous one, was completely extraneous to the notion of "command prompt", because the Macintosh, since its origin to nowadays, has been a "fanatically" User-Centric system: everything is iconic. A side effect of this approach is that MacOS was a pretty hard platform for low-level developers...
    In MacOSX things have dramatically changed: this OS is a powerful Unix-like one, with the beautiful dress that only a Mac can wear: and finally, all you Mac users, here it is: the shell!
    Of course, in MacOSX (and in MacOS "classic" too) there are paths and executable files.
    MacOS1-9 file-system was a very peculiar one: resource fork and data fork for every file, ":" as path components separator (but what "common" user has ever seen a Macintosh path?) and so on.
    MacOSX will use an Unix-like filesystem, I guess (I'm not a Mac user, I like every OS for its beauties - and therefore dislike Microsoft products even if often they give me bread).
    But the key question is: how do I tell the runtime which file it has to execute?
    Fortunately, every modern SO I know adopts a hyerarchical organization of its files. So, indipendently of what is considered the "root" ("C:\", "/" or whatever else), you can "trace" a relative path from your current path (if you use an Unix or URL idiom, "./") and the file you want to reach.
    So, if your java app ("JavaApp.class") is placed in a folder called "MyJavaApp", nested in another folder called "Programs" that you see when you click on the "MacHD" icon, and you can manually launch the Mac app you're interested in clicking on an icon called "MyMacApp Program", placed in a folder called "MyMacApp", nested in another folder called "Programs" that you see when you click on the "MacHD" icon (it's the same folder we said before :-) ), using Unix or URL sintax we have that:
    your java application is at: [...]/MacHD/Programs/MyJavaApp/JavaApp.class
    the Mac application is at:
    [...]/MacHD/Programs/MyMacApp/MyMacApp Program
    The relative path from the former to the latter is, therefore:
    ../MyMacApp/MyMacApp
    where two dots ("..") are the symbol for "parent folder".
    If the situation is similar to above, the code to launch MyMacApp should be something like this:
    import java.io.File;
    File currentDir=new File("");
    //supposing that double dot (..) is the symbol for "parent folder"
    Runtime.getRuntime(
         new File(currentDir,".."
         +File.separator
         +"MyMacApp"
         +File.separator
         +"MyMacApp Program"
         ).getAbsolutePath()
    in a more portable fashion - if you're not sure ".." works
    (? who cares? we're launching a native app :-)) )
    Runtime.getRuntime(
         new File(currentDir.getParent(),
         "MyMacApp"
         +File.separator
         +"MyMacApp Program"
         ).getAbsolutePath()
    );Hope it works... good work!

  • How to launch an application from a website?

    Hi All,
    Can anyone tell me how to launch an application (packaged in a jar) from
    a website?
    I would like to open my application (and pass some arguments) by clicking a special banner or logo
    on a website.
    Regards,
    Stanley

    Google for WebStart and JNLP

  • How to execute another application from java ?

    I want to execute another application ( not java ) from my java application. Is it possible ? How can we do it ? Please guide me...
    thanx

    Hi littlestuart,
    Yes it's possible.
    Your question is frequently asked, please search the forum or google for an answer.
    /Kaj

  • How to run Other application from Java

    I want to run other applications such as IE.exe, notepad.exe from Java? How can I run?

    Dear Friend, the following is the code to open IExplorer from Java Program
    class RunTimeTest {
    public static void main(String args[]) {
    try {
    Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\IEXPLORE.exe");
    catch(Exception e) {
    [\code]
    ALL THE BEST
    Shiva                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to call msword application from java program

    hai every body
    i want to know about OLE in java.
    how can i invoke msoffice application in java code.
    if any body have sanple code for this post for me
    thank you

    There are some bridges available ...
    http://www.google.com/search?q=ole+java+bridge

  • How to launch map application from google map link

    Hello,
    I am looking to find a way to have the map application on an iphone launch when someone opens this link from a website on their phone:
    http://maps.google.com/maps/ms?msa=0&msid=217423717566822591594.0004bb60e527aee0 3991b&mid=1338478668
    It only seems to open the map in safari and I can't find anything about how to change this by searching the web. Any help would be appreciated.
    Thanks,
    Steve

    I do not see the parameters you are using in the list of supported parameters. Can you express that same position using the supported parameters?
    Apple URL Scheme Reference - Map Links
    http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Referen ce/Articles/MapLinks.html
    Parameter
    Notes
    q=
    The query parameter. This parameter is treated as if it had been typed into the query box by the user on the maps.google.com page. q=* is not supported
    near=
    The location part of the query.
    ll=
    The latitude and longitude points (in decimal format, comma separated, and in that order) for the map center point.
    sll=
    The latitude and longitude points from which a business search should be performed.
    spn=
    The approximate latitude and longitude span.
    sspn=
    A custom latitude and longitude span format used by Google.
    t=
    The type of map to display.
    z=
    The zoom level.
    saddr=
    The source address, which is used when generating driving directions
    daddr=
    The destination address, which is used when generating driving directions.
    latlng=
    A custom ID format that Google uses for identifying businesses.
    cid=
    A custom ID format that Google uses for identifying businesses.

  • Can not launch swing application from Java Web Start 1.6.0_37

    I have a dynamic generated jnlp file from a serlvet. When I used Java Web Start to start the swing application, it failed. The exception showed
    com.sun.deploy.net.FailedDownloadException: Unable to load resource: http://xxxx.xx.com:9080/dilpipweb/Test-1.0-SNAPSHOT.jar
         at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
         at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
         at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
         at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
         at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
         at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
         at com.sun.javaws.LaunchDownload$DownloadTask.call(Unknown Source)
         at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
         at java.util.concurrent.FutureTask.run(Unknown Source)
         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    I used janela to validate the generated jnlp file. It was valid. I also checked the tomcat access log, it showed that the Test-1.0-SNAPSHOT.jar file was accessed correctly (with a 200 return code).
    Can anyone help me what was the problem?
    Thanks,

    Hi.
    I got a different problem. My Corba application works in JRE 1.6, but doesn't works in JRE 1.5.X. I got an unexpected error and my console shows:
    getSubjectX500Principal NoSuchMethodError: java.lang NoSuchMethodError
    #### Java Web Start Error:
    #### null
    Can you help me?

  • Launching An Application From Java applet?

    is it possible to run an executable from a java applet (the executable could be in the local machine)? if it is not possible is there any other alternatives (like scripts)?

    Yes, it is possible but it violates the applet security rules. So you have to sign the applet for this to be allowed.

  • How to call a VB application from Java

    Hi,
    does anybody know how to call a VB application from java.
    Would appreciate if you can provide me with an example.
    thanks

    try exec()ing the cad program with the name of the file as a command line parameter...
    Runtime.getRuntime().exec("CADProg.exe Test.prt");
    i have no clue if this will work but it seems like it's worth a try.

  • Launching applications from java code

    I have found a solution to launch applications from java.I thought this will be useful for programmers who want to open a
    1. Browser
    2. Player
    3. Files etc.
    There are 2 solutions :
    I)To use a known application :
    eg: to open windows media player
    String[] cmd = new String[3];
    cmd[0] = "cmd.exe";
    cmd[1] = "/C";
    cmd[2] = "START MPLAYER2.exe "+mediaURL+" /PLAY /CLOSE /FULLSCREEN";
    //eg: mediaURL = "\"D:/project/songs/track1.mp3\""
    // /PLAY /CLOSE /FULLSCREEN this option can be used only for windows media player
    // for any other application use cmd[2] as START apl.exe //apl can be any windows application
    Process p = Runtime.getRuntime().exec(cmd);
    II) To use a default application:
    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
    // url can be any url
    ref: [http://forums.sun.com/thread.jspa?threadID=5203313|http://forums.sun.com/thread.jspa?threadID=5203313]
    [http://www.ericphelps.com/batch/rundll/|http://www.ericphelps.com/batch/rundll/]
    Edited by: veda_sishta on ? ?????, ???? ??:?? ???????
    Edited by: veda_sishta on ? ?????, ???? ??:?? ???????

    To post code, use the code tags -- [code]Your Code[/code] will display asYour CodeOr use the code button above the editing area and paste your code between the {code}{code} tags it generates.
    And make up your mind what file type you're having a problem with. Maybe .asx doesn't have a file association on your computer.
    This works just fine for .m3u:import java.awt.Desktop;
    import java.io.File;
    import java.io.IOException;
    public class Playlist {
       public static void main(String[] args) {
          try {
             Desktop.getDesktop().
                   open(new File("E:/Music/Playlists/test.m3u"));
          } catch (IOException ex) {
             ex.printStackTrace();
    }db
    edit Did you try searching the net for the error you got? ("Invalid menu handle")
    Edited by: Darryl.Burke

  • Close a running application from java........

    Hi all
    I have opened an application say MSWORD from my java class using Runtime.getRuntime(), Now on close button i need to close the application and on the save button of the application i even want to save the application from java command
    The question is HOW????
    please reply,
    Thanx,
    Amitt

    can I open the konsole from java??Yes.
    First you must figure out how to do that from the command line yourself. That has nothing to do with java.
    Note that that how you do that MUST account for the fact that the "command line" is actually a shell. Some commands must be run by running the shell as the actual command and then passing the desired command as an option to the shell (the actual command.)
    Again you can google for examples.

  • How to set iframe src from java dynammically

    Hi,
    Iam calling a servlet from jsp and servlet calls the databse query and returns the value,
    in my jsp i have ifrme, i want to change the source of iframe from java depends on the result from database , and the result must display on the iframe can any one tell me how to do this

    aurelian_cl wrote:
    I need to know how to set environment variables from java
    I want to set from java for example the environment variable "TestVar" with the value "TestValue"!1) That functionality does not belong in an application. You're trying to set environment variables, which are global across all applications, at either the user level as a whole, or across the entire machine (system level). Or, if you're only trying to set a variable active for the current process, you don't need to do that.
    2) Environment variables are not a platform-independent entity, and are thus against the nature of Java.
    My gut feel is that you are designing something in a backwards way, so my point is mainly to point that out, not to try to help you solve that particular problem.

  • Help! How to convert an instance from java.lang.Object to a particula class

    * How to convert an instance from java.lang.Object class to a particular class
    witch is known only at the running time?
    Roster EJB component is make up of RosterHome, Roster and RosterBean.
    RosterHome is the home interface of Roster EJB.
    Roster is the remote interface of Roster EJB.
    RosterBean is the implement of Roster EJB.
    The following code segment is to invoke Roster EJB component.
    String jndiName="roster.RosterHome";
    javax.naming.Context initial = getInitialContext();//getInitialContext() returns a instance of Context.
    Object objref = initial.lookup(jndiName);
    RosterHome home =
    (RosterHome)javax.rmi.PortableRemoteObject.narrow(objref,
    RosterHome.class);
    Roster myRoster = home.create();
    String team="T1"
    String player="Tom"
    myRoster.addPlayer(player,team);
    But, now, all the home interface, the remote interface and the JNDI Name of
    Roster EJB component are not been known at the compiling time. However They are
    known at the running time, throught reading from the XML config file.
    Questions:
    1,How to write code for this case ? or
    2,How to convert an instance from Object class to a particular class witch is known
    only at the running time?
    String jndiName="roster.RosterHome";// in fact, reads from XML file.
    String homeClassName="roster.RosterHome";// in fact, reads from XML file.
    String remoteClassName="roster.Roster";// in fact, reads from XML file.
    javax.naming.Context initial = getInitialContext();//getInitialContext() returns a instance of Context.
    Object objref = initial.lookup(jndiName);
    Object objHome= javax.rmi.PortableRemoteObject.narrow(objref,
    Class.forName(homeClassName));
    /* how to do next?
    }

    I am not sure what you are trying to do. But at some point you should know which methods to call on the remote interfaces. Maybe the method names are stored in the XML file as well or you have a set of standard method names (also consider parameters).
    However, this can be solved by reflection. Look at the java.lang.reflect package, especially java.lang.reflect.Method, and also at java.lang.Class.
    If you are doing this on the app server:
    I've seen posts where people say that reflection is not permitted in EJB, but I don't think so. Check the EJB spec.
    If you are doing this in an application: reflection is always permitted. Probably also in applets and JSP.

  • How to make destop application using java

    how to make destop application using java
    i mean to say when we double click on the exe file the program should lounch the application
    for windows

    when i double click ii got the msg
    Failed to lad main class manifest attribute from
    x/x/xyz.jar
    what exatly it meansIt means that your Manifest.MF for the JAR file should contain an attribute called Main-Class pointing to a class containing the main() method.
    Something like this should be present in META-INF/Manifest.MF :
    Main-Class: MyApplicationMain

Maybe you are looking for

  • Applet doesn´t load in java 7 with next-generation plug-in marked

    I have developed an applet with netbeans 7.1.2 which worked fine until I updated from jvm6 to jvm7. The applet does not load properly unless I uncheck from the configuration of the jvm the checbox plug-in next-generation. Anyone know why in java 6 wo

  • Setting objects to fill the screen

    I'm trying to have my background with various color panels to sit behind text so that when I change the subject I can change the color. Also if the the text extends or shortens I would like to go in and pull up or pull or down this box to cover the e

  • Quick strange beginners design question

    I have a non-crystal report whose format I need to duplicate EXACTLY or all heck will break loose. It contains a simple group with some detail records. I need the count of the detail records on the first line of the details as follows: GH1:         

  • Visual Age 3.5 + windows 2000 + integration KIT 5.1 beta

    I can manage running Weblogic server in VA 35 integration kit with windows 2000. (it's work with NT4). I get the error immediately error : java.lang.unsatisfiedLinkError no server validator in java.library.path

  • Error 1635: This Update Package Could Not Be Opened

    Recently I've been getting an Adobe Update Failed error popping up in my task bar: I've tried the Microsoft FixIt listed as a solution for this error on the following page, but it made no difference: http://helpx.adobe.com/acrobat/kb/update-errors-ac