Invoking jvm from a java application

hello people,
i would like to run a java application 'B' from within another java application 'A'. i have a thread sub class that does this. it is given
below: (please pay attention to the run method)
import java.io.*;
import javax.swing.*;
public class InvokingThread extends Thread
private File n=null;
private JTextArea outputArea;
private String message="",action="";
private String pathToBin,errors,input,classpath;
private EvaluatorClient clientRef;
//initialize InvokingThread object
public InvokingThread(File name,String act,String path,String cp)
outputArea=new JTextArea(10,25);
outputArea.setEditable(false);
outputArea.setLineWrap(true);
n=name;
pathToBin=path;
classpath=cp;
action=act;
System.out.println((action.equals("compile"))?"compiling":"executing");
public void setClientRef(EvaluatorClient r)
clientRef=r;
//process action
public void run()
Process proce=null;
try
if(action.equals("compile"))
proce = Runtime.getRuntime().exec(pathToBin+"/javac "+n);
else if(action.equals("execute"))
proce = Runtime.getRuntime().exec(pathToBin+"/java "+classpath+" "+n); //run application
Thread.sleep(5000);
byte[] errorData = new byte[proce.getErrorStream().available()];
proce.getErrorStream().read(errorData);
byte[] inputData = new byte[proce.getInputStream().available()];
proce.getInputStream().read(inputData);
errors = new String(errorData);
input = new String(inputData);
System.out.println((errors.length()>0)?"error string"+errors:"no errors");
System.out.println((input.length()>0)?"input string"+input:"");
if (errors.length() == 0 & action.equals("compile"))
outputArea.setText("Compiled successfully");
if(clientRef!=null)
if(!clientRef.isTimeUp())
clientRef.toggleMenuItemState(4,true);
clientRef.toggleMenuItemState(5,true);
clientRef.compilationOutcome("success");
JOptionPane.showMessageDialog(null,new JScrollPane(outputArea));
else if (errors.length() != 0 & action.equals("compile"))
outputArea.setText("Compile Errors:\n" + errors+""+input);
if(clientRef!=null)
clientRef.compilationOutcome("failure");
JOptionPane.showMessageDialog(null,new JScrollPane(outputArea));
else if(action.equals("execute"))
if(errors.length() != 0)
outputArea.setText("Runtime errors:\n" + errors);
JOptionPane.showMessageDialog(null,new JScrollPane(outputArea));
else if(input.length()!=0 )
outputArea.setText(input);
JOptionPane.showMessageDialog(null,new JScrollPane(outputArea));
catch(Exception e)
e.printStackTrace();
System.out.println("thread awake,invoking thread terminating");
}//end run
The above code worked when i used it with the rest of my program.
as we can see the thread waits for 5 seconds before it reads the inputstream and error stream of the sub process returned by Runtime.getRuntime().exec(). But what happens after the thread terminates; i am unable to process subsequent runtime messages/exceptions from the application 'B'.
so my question goes thus: is there a way that my thread can continually listen to the error stream and input stream of the sub process while application 'B' is still running so as to process any messages returned by java form the application 'B' ? or is there a better way of doing what i set out to achieve i.e running a java application from within another java application
timi

Runtime.getRuntime().exec("rundll32
url.dll,FileProtocolHandler
mailto:[email protected]&subject=Foo&body=Bar");yawmark, where do you get such information from? (in all seriousness :-) )
How (the hell) can you find out what args to pass to a program?
and is "FileProtocolHandler" a place-holder? if so what for?
thanks, :)
lutha

Similar Messages

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

  • 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

  • Is it possible to create triggers in sybase from jdbc (java application)?

    We are in the need to create a triggers in the database (sybase) from JDBC (java application)?
    Please send me pointers or articles related to this.
    Thanks in advance,
    Kri

    A trigger is NEVER explicitly called, from any environment.
    It is implicitly called when you invoke the operation that it's a trigger for.
    Whether you're using Java or anything else to invoke that operation makes no difference whatsoever.

  • Executing any other applications from a java application

    how can i execute or invoke other applications on the pc
    from a java application?

    Runtime.getRuntime().exec("dir");

  • 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 can i call a jasper report from a java Application

    Hi,
    i am chiranjit , currently i working in a web based ERP project, in this project as a report building tool we are using JasperReport wih eclipse plugin . in eclipse report's are generating very well but i am unable to call that report from a java application because i have no idea about the How to call a Jasper Report from a Java Application . so please send me the necessary class names, jar files names and programe code as early as possible.
    Chiranjit

    Ahh, kind of a duplicate thread:
    http://forums.java.sun.com/thread.jspa?threadID=631642
    @OP. You could have clarified your original post and the relationship of your question to java. You did not need a new thread.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How can i call a VB6 project from my java application using JNI

    hi
    can anyone tell me the procedure of calling a VB6 project from any java application using JNI
    if anyone does know then tell me the detail procedure of doing that. I know that i have to create a dll of that VB6 project then to call it from the java application.
    if anyone know that procedure of creating dll file of an existing VB6 project please reply
    please if anyone know then let me know

    Ahh, kind of a duplicate thread:
    http://forums.java.sun.com/thread.jspa?threadID=631642
    @OP. You could have clarified your original post and the relationship of your question to java. You did not need a new thread.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • CorrelationSet error while invoking Bpel from a java appli

    Hi There,
    I'm trying to send a signal from a java application to a bpel process (already instanciated before) and I get the following error :
    [Erreur ORABPEL-10015] : propriété de corrélation non résolue
    [Description] : à la ligne 25 de "/oracle/product/10.1.2/.../myProjectConvertPdf.bpel", la propriété de corrélation "{http://xmlns.oracle.com/myProjectConvertPdf/correlationset}filename" du correlationSet "CorrelationSet_signalConvOk" n'est pas définie.
    [Solution potentielle] : assurez-vous que la propriété "{http://xmlns.oracle.com/myProjectConvertPdf/correlationset}filename" est définie dans l'un des fichiers WSDL référencés.
    My java application is designed to get the value of the correlation parameter from another source (the bpel process calls a webservice a webservice in another virtual machine and transmits the parameter value by a database table or a file)
    My file .bpel contains :
    <receive name="Receive_signalConvOk" partnerLink="signalConvPdfOk" portType="client:projectSignal" operation="receiveSignal" variable="Receive_signalConvOk_receiveSignal" createInstance="no">
    <correlations>
    <correlation initiate="no" set="CorrelationSet_signalConvOk"/>
    </correlations>
    </receive>
    the correlation is defined as followed :
    <correlationSets>
    <correlationSet name="CorrelationSet_signalConvOk" properties="ns1:filename"/>
    </correlationSets>
    and the property alias :
    <definitions
    name="properties"
    targetNamespace="http://xmlns.oracle.com/myProjectConvertPdf/correlationset"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
    xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    >
    <bpws:property name="filename" type="xsd:string"/>
    </definitions>
    My java appli calls the bpel process by the following code :
    String xml = "<filename xmlns=\"http://xmlns.oracle.com/myProjectConvertPdf\">"+parameterValue+"</filename>\n";
    NormalizedMessage nm = new NormalizedMessage( );
    nm.addPart("payload", xml );
    deliveryService.post(nomProcessBpel,
    null,
    "signalConvPdfOk",
    null,
    nomOpBpel,
    nm);
    My first problem is obviousy the error message and my second problem is that I don't know how to transmit the correlation parameter in the request my java appli does to the bpel process.
    Thanks in advance for your help

    Hi,
    Refer below thread and links for more information. Hope this should help you guys.
    ESB Not allowing to call Secured Service
    Regards

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

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

  • How to call pdf forms developed in ABAP from WD Java application?

    Hi
    I have a web dynpro ABAP application that that is responsible for generating PDF forms for all other applications (WD ABAP and WD Java).
    How can I call the pdf forms generated by the WD ABAP application from WD Java application in a separate window?
    These forms are to be called on click of a "Print" button. Also, these forms are non interactive.
    Kindly let me know if you need any other information.
    Regards
    Vineet Vikram
    Edited by: vineet vikram on Jun 24, 2009 7:28 AM

    in addtion to Nikhil's response. you can write following code on action of print button:
        IWDWindow window = wdComponentAPI.
            getWindowManager().createExternalWindow(
                  "<ABAP Application URL>",
                  "<Title for window>",
                  false);
       window.open();
    to Close the application, you can use the window close or u can fire an event to close current window.
    Abhinav

  • Example-- Call RFC from external Java Application

    Update: I need code example to call RFC from External Java application. Can onybody help me?                                                      
    RGDS
    RP
    hi all.
    i want to create my own log for each interface.
    i saw this blog:
    /people/michal.krawczyk2/blog/2006/09/20/xi-abap-mapping-logs--more-standard-better-visibility
    my doubt is how to catch the error that i see in SXI_MONITOR y put it in a Sub-Objetc.
    For example: in sxi_monitor i get the error for my interface NMUCustomer: "No receiver could not be found" or "Error Mapping Traformation".
    I created an Object called ZNMUCUSTOMER and a Sub-Objetc called ZERROR.
    what i must do to get the error I see in monitor and assign it to Sub-Object??
    Rgds.
    Message was edited by:
            Rodrigo Pertierra
    Message was edited by:
            Rodrigo Pertierra
    Message was edited by:
            Rodrigo Pertierra

    Hi,
    Oh, you are using ABAP mapping ......
    then use the following in ABAP mapping ..
    TRACE1,TRACE2,TRACE3.... for trace level 1,2,3......
    http://help.sap.com/saphelp_nw04/helpdata/en/ba/e18b1a0fc14f1faf884ae50cece51b/content.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/5c46ab90-0201-0010-42bd-9d0302591383
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/866ce290-0201-0010-338f-b8c3553aaa0f
    Regards
    Chilla

  • How can access MS Outlook Calender information  from my Java application.

    People schedule meeting with some data on regular basis.
    I need to access the Exchange server from my Java application and get the meeting dates along with other data pertaining to meeting.

    I had the same problem, and I dont think (as far as my knowledge goes) there is any freeware that will enable Java to access Exchange server. But there are some commercial products that are available.
    Chk this link as an example: http://www.compoze.com/products_hme_desc.html
    good luck in the research
    -kms

  • Can we control the top level navigation in portal from a java application

    Hello,
    I am having a scenario where User logged in to portal and assigned with 2 roles (HOME , ISA(Java application)). When user opened a form in ISA (Java application) and tried to enter the data in form and moved to another tab (e.g. HOME) in top level navigation.
    When user come back to ISA (Java application) TAB , we show the page where he left earlier. I would like to know if user click any other TAB in top level navigation (Role assigned to him) while working on a page in ISA(Java application) is there any way we can catch that event before he leaves from ISA (Java application JSP page) to other TAB?
    How can we control the top level navigation events in the portal from a java application .Since Top level navigation is seperate par file.
    Thanks,
    RN

    Dear Rajesh,
    Top Level and detailed navigation values comes with iteration in the respective par file.
    Please check the par file and based on the value (i.e tab name) selected, you can write your code.
    Best Regards
    Arun Jaiswal

Maybe you are looking for

  • Paper Profiles

    I have a G4 Mac, System 10.4.10 and a R800 Printer. The prints are far too dark. I had this problem when using the beta Lightroom and solved it when I installed the Epson profiles. I now have a mismatch in the profiles listed under Lightroom Print mo

  • My lightroom navigation bar is not showing up. How do I get it back?

    My lightroom navigation bar at the top is not showing up. How do I get it back?

  • Doubt in using UNION between queries

    HI, Here is my query, SELECT      NULL AS NAME,      NULL AS VDATE,      'SP' AS OBJECTS FROM DUAL UNION SELECT      'MURALI' AS NAME,      SYSDATE AS VDATE,      NULL FROM DUAL; The Result from the query is NAME----VDATE---OBJECTS MURALI-- 12/1/2007

  • TS1424 I get error code R6034. Any suggestions?

    I get error code R6034 while trying to download Itunes. Any suggestions?

  • How to avoid users forward automatically emails to external domains

    Hello In the user preferences for the email, the user can create new server side rules for his account. One of this rules can be "forward every received email to another account". We would like to restrict this possibility to only our local domain. T