Launching another Swing application from existing one using Runtime.exec()

Hi,
I have two separate Swing applications, say A and B. I need to launch B from A using Runtime.exec() - essentially I am launching another VM instance from one VM. I am encountering strange problems - B's main window comes up, but GUI doesn't update; sometimes B comes up and GUI updates, but huge memory leaks happen. All the problems with B go away once A is shut down. It almost looks like both the instances of VM are sharing (or competing for) the event thread. Any comments will be of great help. Thanks.
note: There is no problem launching B if A is a console java application (i.e. no Swing GUI).

Do you have to have the second application running in a seperate VM (process)? If not completely neccesary, then you can just invoke the static main() of the second class. If the type of the second class isn't known untill run-time, you can use Reflection to invoke the method.
Miguel

Similar Messages

  • How to copy .gif files from one dir to another using runtime.exec

    hello sir/madem,
    i want to copy some gif and jepg files from one directory to another dir using swing.
    when i tried with using runtime.exec(String[]) i am getting the following error.
    anybody please tell me what is the problem in my program
    java.io.IOException: CreateProcess: ren c:/windows/desktop/copy.java c:/windows/
    cc.java error=0
    code:
    public class copy
         public static void main(String[] args)
              try{
                   String s[]=new String[3];
                        s[0]="ren";
    s[1]="c:/windows/desktop/copy.java";
    s[2]="c:/windows/cc.java";
              Runtime rt=Runtime.getRuntime();
    Process p=rt.exec(s);
              int i=p.waitFor();
              System.out.println("i is "+i);
              }catch(Exception e){System.out.println(e);}
    please mail me to [email protected]
    thanks in advance
    samba reddy
    india

    why use the Runtime? There are methods for this in the IO package ...

  • How to Start/Launch another WD application using a link.

    Hi, I've been trying to see if there's an official way that I can launch another WD application using a link from within an application where the applications are not in the same deployable object.
    P.S.  I've seen the other thread of how to do it when the applications are within the same deployable object.
    Thanks in advance as always,

    Hi Michael,
    of course it does, so the question should be:
    "Hey, how do it get the application URL of a WD application without hardcoding the server name, port or whatever?"
    This is simple:
       * Return is the application URL for the specified <code>deployableObjectPart</code> with appended 
       * URL parameters given by <code>urlParameters</code>. All key/value pairs in the map must
       * be of type java.lang.String.
       * @param deployableObjectPart a deployable object part representing a Web Dynpro application
       * @param urlParameters key/value pairs added as URL parameters; they must be of type String
       * @return the application URL for the specified <code>deployableObjectPart</code> with appended 
       * URL parameters given by <code>urlParameters</code>
       * @throws WDURLException if the URL couldn't be generated
       * @see com.sap.tc.webdynpro.services.sal.url.api.WDURLGenerator#getApplicationURL(WDDeployableObjectPart)
      public static String getApplicationURL(WDDeployableObjectPart deployableObjectPart, Map urlParameters) throws WDURLException {
        return AbstractManager
          .getServerPlatformImplementation()
          .getURLGeneratorFactory()
          .getURLGenerator()
          .getApplicationURL(deployableObjectPart, urlParameters);      
    or if you would like to get it load balanced:
       * Return is the workload balanced application URL for the specified <code>deployableObjectPart</code> with appended 
       * URL parameters given by <code>urlParameters</code>. All key/value pairs in the map must
       * be of type java.lang.String.
       * @param deployableObjectPart a deployable object part representing a Web Dynpro application
       * @param urlParameters key/value pairs added as URL parameters; they must be of type String
       * @return the workload balanced application URL for the specified
       * <code>deployableObjectPart</code> with appended URL parameters given by <code>urlParameters</code>
       * @throws WDURLException if the URL couldn't be generated
       * @see com.sap.tc.webdynpro.services.sal.url.api.WDURLGenerator#getWorkloadBalancedApplicationURL(WDDeployableObjectPart)
      public static String getWorkloadBalancedApplicationURL(WDDeployableObjectPart deployableObjectPart, Map urlParameters) throws WDURLException {
        return AbstractManager
          .getServerPlatformImplementation()
          .getURLGeneratorFactory()
          .getURLGenerator()
          .getWorkloadBalancedApplicationURL(deployableObjectPart, urlParameters);     
    Before i forget it to mention, these are two methods of the WDURLGenerator API. There are others where you don't have to specify the deployableObjectPart, you can use DPO name and name of application as parameters instead.
    Hope that helps.
    Best regards
    Stefan
    PS: This was my 2nd attempt, i hope i got you right now...

  • Launching another VM instance using Runtime.exec()

    Hi,
    I have two separate Swing applications, say A and B. I need to launch B from A using Runtime.exec() - essentially I am launching another VM instance from one VM. I am encountering strange problems - B's main window comes up, but GUI doesn't update; sometimes B comes up and GUI updates, but huge memory leaks happen. All the problems with B go away once A is shut down. It almost looks like both the instances of VM are sharing (or competing for) the event thread. Any comments will be of great help. Thanks.
    note: There is no problem launching B if A is a console java application (i.e. no Swing GUI).

    I have recently had the same problem, especially with the part where it seems like the two applications are sharing or competing for the same event thread. Sometimes my application B hangs like it is stuck waiting for an event. Sometimes I can get it to unhang by moving the app window around or minimizing it. If it does break free, all the queued events occur in rapid succession. Anybody have any clue what's going on here? It's pretty annoying.

  • Debug the swing application from eclipse

    Hi
    I had a swing application, to create a exe file i build the application using using build.xml. To run the application we need to open the exe file.
    I want to debug this swing application from eclipse. Can anybody please tell me how to debug this application.
    Note: I can able to debug simple swing application. But i can't able to debug this application.
    Thanks
    mindus

    If it's an actual .exe--that is, if you've compiled it to a native Windows executable--then you can't debug it using a Java debugger (such as the one in Eclipse).
    If, on the other hand, you just have a .jar file or a bunch of .class files, then you can debug this app the same way you debugged the other one.
    If you don't provide more details about what you actually did and what exact problems you're having ("I can't do it" contains no useful information whatsoever), then it's impossible to provide any more detailed advice than this.

  • Can we call simple a java application from any one of this AS adapters

    Can we call a simple java application from any one of this AS adapters?
    Prakash
    Message was edited by:
    user629857

    You can achieve this using LiveCycle PDF Generator JAVA API. You can find required code here:
    Adobe LiveCycle * Quick Start (SOAP mode): Converting a Microsoft Word document to a PDF document using the Java API
    In parameters:
    //Set createPDF2 parameter values
    String adobePDFSettings = "Standard";
    String securitySettings = "No Security";
    String fileTypeSettings = "Standard OCR";
    "Standard OCR" file type setting will run OCR on input pdf. In the code, instead of doc file provide a pdf file. Resultant pdf will be searchable PDF i.e OCRed PDF.
    Feel feel to ask any further questions.

  • Calling another ITS service from existing ITS service

    Hi to Everyone,
    I would like your advice on calling another ITS service from existing ITS service.
    From my current ITS service eg. "Z_TESTA", i wish to call another ITS service "Z_TESTB". The problem is that it always prompt for userid and password when i called the 2nd ITS service. However, user already enter the password & id when they login to the 1st ITS service. Is there a way to call this new ITS service w/o the userid & password prompt again?
    Below is the codes that we used to call the new ITS service:
    (a) "http://.../scripts/wgate/webgui/!?~transaction=z_testb"
    OR
    (b) "http://.../scripts/wgate/z_testb/!"
    We used both method (a) and (b) but same outcome. Thank you in advance!
    YanaJ

    Hi YanaJ,
    in order to skip a manual login you have to have the credentials somewhere. If you disabled cookies, what I told you will not work. Another possibility would the usage of X509 client certificates. But this requires that you have a setup that distributes the certificates of all of your users. I personally nether setup such scenario. Maybe someone other can explain what you have to do.
    Best regards,
    Klaus

  • Problems After shifting swing application from jdk1.3 to 1.4

    hi,
    i have shifted my Swing application from jdk1.3 to 1.4, some component settings changed in j2se1.4. are listed below
    1). i have added JComboBox to JPanel using BoxLayout, in jdk1.3 it is normal where as in 1.4 comboBox height is increased to panel height.
    Sample code
    (in a Panel)
         setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    add(getYearComboBox());
         add(getMonthNameComboBox());
         add(getDayOfMonthComboBox());
    2). in jdk1.3 the icon which is set to JFrame is visible in the JOptioPane.showConfirmationDialog() also, but in 1.4 the icon is not visible in conformation dialog box.
    Sample Code
    in a JFrame's constructor
    public OptionPaneTest()
    ImageIcon icon = new ImageIcon("icon.gif");
    setIconImage(icon.getImage());     
    setSize(250,100);
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
    setVisible(true);
    JOptionPane.showMessageDialog(this,"hai", "Hai",JOptionPane.WARNING_MESSAGE);
    3). the Labels added to the panel or frame are displaying in light blue color with jdk1.3 and the same label displaying in black with j2se1.3
    Sample Code
    in a JPanel
    setLayout(new BorderLayout(20, 20));
    add(new JLabel("Testing Label Color"), BorderLayout.CENTER);
    please send solution to any or all.
    thanks in advance,
    Pavan.DV

    Thanks for your sugession.
    You realized me by showing the fact that there are no many classes
    Keep suggesting like this.
    I don't even know how to see the API documentation Before you told me.
    Don't take any issue as simple thing and never give foolish suggessions like this.
    If you know the Answer then share it or else musukoni kurcho ra

  • How to invoke ADF custom application from existing R12 EBS application

    Hi Guru's,
    We have a requirement to invoke ADF custom application from existing EBS R12.1.3 application.
    Is there any documentation provided by ORACLE or any online help on how to integrate/invoke ADF pages from existing EBS application?
    And can we pass any EBS session level parameters like(user info, language, operating unit etc) to ADF layer while invoking the ADF application?
    I have thoroughly searched the forums and got some info related to JAAS security links and all. but i am looking for exact integration specific steps.
    Any help in this regard is a great help!!
    Thanks alot for your help!!
    Subba.

    lets raise your question over here
    JDeveloper and ADF
    Thanks
    vamshi.

  • I have purchase some applications from app store using my VISA DEBIT card.

    Hi Sir,
    I have purchase some applications from app store using my VISA DEBIT card. Apps downloaded successfully. After download when I want change my payment method again to none, it says “enter a new VISA CARD to clear outstanding. I am entering my VISA DEBIT card no. but it says again to enter new card no.
    When I check my Debit card statement there no payment made to apple, but apps downloaded on my iphone.
    And when open itunes and want download more apps it say to enter CARD no.
    Please help me.
    Gursharan Singh

    Contact iTunes Customer Service and request assistance...
    Apple  Support  iTunes Store  Contact Us

  • Can we run a java application using Runtime.exec()?

    Can we run a java application using Runtime.exec()?
    If yes what should i use "java" or "javaw", and which way?
    r.exec("java","xyz.class");

    The best way to run the java application would be to dynamiically load it within the same JVM. Look thru the class "ClassLoader" and the "Class", "Method" etc...clases.
    The problem with exec is that it starts another JVM and moreover you dont have the interface where you can throw the Output directly.(indirectly it can be done by openong InputStreams bala blah............). I found this convenient. I am attaching part of my code for easy refernce.
    HIH
    ClassLoader cl = null;
    Class c = null;
    Class cArr[] ;
    Method md = null;
    Object mArr[];
    cl = ClassLoader.getSystemClassLoader();
    try{
         c = cl.loadClass(progName.substring(0,progName.indexOf(".class")) );
    } catch(ClassNotFoundException e) {
    System.out.println(e);
         cArr = new Class[1] ;
         try{
         cArr[0] = Class.forName("java.lang.Object");
         } catch(ClassNotFoundException e) {
         System.out.println(e);
         mArr = new Object[1];
         try{
         md = c.getMethod("processPkt", cArr);
         } catch(NoSuchMethodException e) {
         System.out.println(e);
         } catch(SecurityException e) {
         System.out.println(e);
    try {            
    processedPkt = md.invoke( null, mArr) ;
    } catch(IllegalAccessException e) {
              System.out.println(e);
    } catch(IllegalArgumentException e) {
              System.out.println(e);
    }catch(InvocationTargetException e) {
              System.out.println(e);
    }catch(NullPointerException e) {
              System.out.println(e);
    }catch(ExceptionInInitializerError e) {
              System.out.println(e);
    }

  • IOException File not found - While using Runtime.exec

    Hey All,
    I have written a Java application which needs to start up another external application. I have executables for that external application for different platforms (Win32, PPC and Linux). When the Java application is started it detects the OS and starts up the right executable according to the OS. The executable loads up fine on Windows without any problems. But in both Linux and Max OS X I get this exception:
    java.io.IOException: java.io.IOException: "/home/vilas/Documents/Project/build/CLISP/linux/lisp.run": not found
            at java.lang.UNIXProcess.<init>(UNIXProcess.java:143)
            at java.lang.Runtime.execInternal(Native Method)
            at java.lang.Runtime.exec(Runtime.java:566)
            at java.lang.Runtime.exec(Runtime.java:428)
            at jplan.communication.lispserver.LispServer.startupServer(LispServer.java:143)
            at jplan.communication.lispserver.LispServer.run(LispServer.java:109)
            at java.lang.Thread.run(Thread.java:534)lisp.run has all the necessary permissions. If I copy the string (/home/vilas/Documents/Project/build/CLISP/linux/lisp.run) and paste it in a terminal and press enter, the application starts up fine without any problems!! Can you please tell me what could be going wrong?
    The following extra information maybe helpfull:
    1) I use the exec(String command, String[] envp, File dir) version of exec.
    2) The complete format of the command is as follows (one long string):
    "/home/vilas/Documents/Project/build/CLISP/linux/lisp.run" -B "/home/vilas/Documents/Project/build/CLISP/linux" -M "/home/vilas/Documents/Project/build/CLISP/linux/lispinit.mem" -i loader.lisp
    Thanks in advance for your time and efforts.

    I found the problem after extensively searing the forums (looking upto page 4 !! of the results). The problem was that I was using quotes to surround the paths in the command. If you copy and paste it in a terminal it will work fine but it does not work with runtime.exec. I am not sure, but I think the reason is that when a terminal is used, some pre-processing of the commands take place before they are passed onto the OS(shell). But while using runtime.exec, that pre-processing is not peformed and therefore some things will not work.
    In order to fix the problem, I use quotes only when the OS is windows. In other cases(OS X, Linux) I escape the spaces i.e. replace " " with "\ ".
    PS: The executable is a binary compiled from C code.

  • Opening a new browser using Runtime.exec()...

    I am trying to open a new IE browser window (from Windows) using Runtime.exec( ) command. The problem is that it uses the existing browser window instead of opening a new window. (opens a new window only if there isn't any other browser window)
    Here is the snippet of code that I am using to do this:
    String WIN_PATH = "rundll32";
    String WIN_FLAG = "url.dll,FileProtocolHandler";
    String url = "http://www.cnn.com";
    String cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
    Process p = Runtime.getRuntime().exec(cmd);
    Thanks in advance.
    -Kishore

    >
    opening browser window seems to be easy task, >Even easier with [Desktop.browse(URI)|http://java.sun.com/javase/6/docs/api/java/awt/Desktop.html#browse(java.net.URI)].
    >
    ..can someone help me with closing browser window from java?>Which browser window?
    If you're app. opens a page that you control, it can be done from the web page. See [Have a Java button close the browser window|http://www.rgagnon.com/javadetails/java-0282.html] or the JS based [Close the browser|http://www.rgagnon.com/jsdetails/js-0079.html].
    If you do not control the page, don't close it - the user knows where the little 'x' button is.
    As an aside, despite being opposite ends of the one question, I do not consider this question to be 'part' of the current thread. I think you would have been better off starting a dedicated thread and explaining more fully what the use case is (and adding lots of Dukes).

  • Executing bat file without using Runtime.exec()??

    Hi all
    From my java App ,I am running a bat file. This is what I did:
    When I press 'execute' button inside my App, it runs a bat file through Runtime.exec() method. Since exec() runs it through cmd.exe, get a DOS window when I press Execute button. If I manually runs my app from command promt , I dont get it. But I have to create a short cut of my main class in the desktop. This is happening when I run my app from desktop icon.
    Now I want to eleminate DOS popup everytime I press execute button. Would anyone pls give an idea how to run bat file without using Runtime.exec()? Any suggestion will be helpful.
    Thanks

    jscell
    Thanks for taking time to answer to my problem .
    Here is what my problem: I create a shortcut of my main class in the desktop. Through this shortcut ,I run my java App. My App has a execute button, When I press this button , It run another bat file through Runtime.exec() method, and show some result in the result PAnel. NOw what happen , I get a DOS command window , everytime I press execute button. , Which is very annoying . But If I run my App thorugh command promt by executing: "java myApp", then I dont get this DOS popup. But I have to create a shortcut in the desktop, so other can use it conveniently.
    NOw I am not sure why I am getting this DOS window in the middle of my Application. IS it for using Runtime.exec() method? or for running bat file through my application? Can anyone pls tell me? I am kind of new to java, and I am learning lot of stuff from this forum .
    Would u pls suggest me about how to eleminate this DOS popup when I press execute button.
    Regrds

  • Trying to run external script using Runtime.exec

    Hey,
    I am trying to use Runtime.exec(cmd, evnp, dir) to execute a fortran program and get back its output, however it seems to always be hanging. Here is my code snippet :
                Process process = Runtime.getRuntime().exec(
                      "./fortranCodeName > inputFile.txt" , null, new File("/home/myRunDir/"));
                InputStream stream = new InputStream(process.getInputStream());
                InputStream error = new InputStreamr(process.getErrorStream());
                BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stream));
                BufferedReader erroutReader = new BufferedReader(new InputStreamReader(error));
                System.out.println(stream.available());  //returns 0
                System.out.println(error.available());     //returns 0
                while (true) {
                    String line1 = stdoutReader.readLine();  //hangs here
                    String line2 = erroutReader.readLine();
                    if (line1 == null) {
                        break;
                    System.out.println(line1);
                    System.out.println(line2);
                }I know for a fact that this fortran code prints out stuff when run it in terminal, but I don't know if I have even set up my Runtime.exec statement properly. I think I am clearing out my error and input streams with the whole reader.readLine bit I have above, but I am not sure. If you replace the command with something like "echo helloWorld" or "pwd", it prints out everything properly. I also am fairly confident that I have no environmental variables that are used in the fortran code, as I received it from another computer and haven't set up any in my bash profile.
    Any Ideas?

    Okay, so I implemented the changes from that website (thanks by the way for that link, it helps me understand this a little better). However, my problem is still occuring. Here is my new code:
                class StreamThread extends Thread {
                InputStream is;
                String type;
                StreamThread(InputStream is, String type)
                    this.is = is;
                    this.type = type;
                public void run()
                    try
                        InputStreamReader isr = new InputStreamReader(is); //never gets called
                        BufferedReader br = new BufferedReader(isr);
                        String line=null;
                        while ( (line = br.readLine()) != null)
                            System.out.println(type  +">"+  line);
                        } catch (IOException ioe)
                            ioe.printStackTrace();
            try {
                Process process = Runtime.getRuntime().exec(
                      "./fortranCodeName" , null, new File("/home/myRunDir/"));
                StreamThread stream = new StreamThread(process.getInputStream(), "OUTPUT");
                StreamThread errorStream = new StreamThread(process.getInputStream(), "ERROR");
                stream.start();
                errorStream.start();
                int exitVal = process.waitFor(); //hangs here
                System.out.println("ExitValue: " + exitVal);

Maybe you are looking for

  • XML validation with DTD

    Hi Team, I want to validate the XML content with DTD refered in the XML. I have problem now is my DTD are present in a jar file. How do I need to set systemid to the input source so that it works. <!DOCTYPE test SYSTEM "test.dtd"> SAXParserFactory fa

  • Programatically creating users, roles and insert them into Jazn xml

    Hi All, I am using ADF 11G and ADF BC to develop my application. Whenever a user is created an entry will go into OID and into DB. Admin will apply the roles and users for that roles through application. Once the administrator assigns the roles, the

  • Which Mac Pro System works best with Premiere Pro CC?

    I am looking to upgrade my 12 core tower to the newer Mac Pro. I am wondering if anyone out there has suggestion as to what makes the most sense financially in terms of which  flavor of Mac Pro to get? For example, Is there a significant speed increa

  • WAD Doubt

    Hi All, I stumbled upon an issue on WAD. First page of my WAD report should show only the Radio buttons. Using that I will open different queries. But when I execute the report I am getting all the variable selection screen of all the queries embedde

  • Projects won't open

    Just as I finished a project, the program shut down with an error message.  I re-opened the program, but the project will not open.  It says "Loading project" but nothing happens.