Methode who execute an other java program

Hi!
Is there anyone who know a method who can execute an other java program from an applet?
Thanks
Julien

Depends where the classes of the other program are located. A java program is just a collection of classes, with one particular one regarded as the main one. If you know the main class of the other program at compile time you can just invoke it like any normal method.
Something like:
MyOtherProgram.main(new String[]{"first parameter", "second parameter"});(assuming that it's just a standard "command-line" kind of program.)
If you don't know the class name at until runtime it's still farly straightforward:
something like
import java.reflect.*;
String theOtherProgram = ......
Class otherP = Class.forName(theOtherProgram);
String [] params = {"first parameter", "Second parameter"};
Method theMain = otherP.getMethod("main", new Class[]{params.getClass()));
theMain.invoke(null, params);

Similar Messages

  • Getting resultset from some other java program

    how could i getting resultset from some other java program?
    plz

    a resultset is directly linked to your (prepared) query.
    for performance(and synchronization) reasons, you do want to retrieve the data as fast as possible and then release it.

  • Execute an external java program with Runtime, problem with classpath

    Hi,
    I m calling an external java program by the command:
    Runtime.getRuntime().exec("java -classpath \"library/*\" org.mypackage.TestMainProgram param1 c:/input/files c:/output/files");All my classes are stored in the relative directory "library", and it contains ONLY .jar files. However, I keep getting errors like:
    "java.lang.NoClassDefFoundError: library/antlr/jarCaused by: java.lang.ClassNotFoundException: library.antlr.jar     at java.net.URLClassLoader$1.run(URLClassLoader.java:200)     at java.security.AccessController.doPrivileged(Native Method)     at java.net.URLClassLoader.findClass(URLClassLoader.java:188)     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)     at java.lang.ClassLoader.loadClass(ClassLoader.java:252)     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)Could not find the main class: library/antlr.jar. Program will exit.Exception in thread "main" where "antlr.jar" is a jar file in "library". It is there but still the program keeps complaining it cannot be found. The problem applies to any jars in "library", ie.., if i have "mylib.jar" then it will complain "NoClassDefFoundError: library/mylib/jar".
    Could anyone give some pointers please?
    Many thanks!
    Edited by: 836590 on 14-Feb-2011 09:03

    836590 wrote:
    Hi,
    I m calling an external java program by the command:
    Runtime.getRuntime().exec("java -classpath \"library/*\" org.mypackage.TestMainProgram param1 c:/input/files c:/output/files");All my classes are stored in the relative directory "library", and it contains ONLY .jar files. However, I keep getting errors like:
    "java.lang.NoClassDefFoundError: library/antlr/jarCaused by: java.lang.ClassNotFoundException: library.antlr.jar     at java.net.URLClassLoader$1.run(URLClassLoader.java:200)     at java.security.AccessController.doPrivileged(Native Method)     at java.net.URLClassLoader.findClass(URLClassLoader.java:188)     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)     at java.lang.ClassLoader.loadClass(ClassLoader.java:252)     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)Could not find the main class: library/antlr.jar. Program will exit.Exception in thread "main" where "antlr.jar" is a jar file in "library". It is there but still the program keeps complaining it cannot be found. The problem applies to any jars in "library", ie.., if i have "mylib.jar" then it will complain "NoClassDefFoundError: library/mylib/jar".
    Could anyone give some pointers please?
    Many thanks!
    Edited by: 836590 on 14-Feb-2011 09:03First, if you run from the command line
    java -classpath "library/*" org.mypackage.TestMainProgram param1 c:/input/files c:/output/filesfrom the parent directory of library, does it work?
    Despite what I said to Kayaman about Runtime.exec not expanding the asterisk, it looks like that's what's happening, so that you're getting
    java -claspath library/aaaa_something_before_antlr.jar library/antlr.jar library/bbb.jar library/ccc.jar  org.mypackage.TestMainProgram param1 c:/input/files c:/output/filesThat is, it *is* expanding the asterisk to a list of files in the directory, and the first one is being taken as the classpath, and the second one--library/antlr.jar is being taken as the class to execute. I'm certain this doesn't happen on Linux, so it must be a Windows thing.
    Two suggestions:
    1) Try single quotes instead of double.
    2) Try the exec that takes an array
    Runtime.getRuntime().exec(new String[] {"java", "-classpath", "'library/*'", "org.mypackage.TestMainProgram", "param1", "c:/input/files", "c:/output/files");Edited by: jverd on Feb 14, 2011 9:41 AM

  • How to launch executable from a java program

    In c++ we can use a function WinExec to execute exe from a c++ program.
    Is there a way to launch executables using java program. Lets say I have one executable with name "myexecutable.exe" and a java program "myprogram.java". How can I launch "myexecutable.exe" from the java program.
    Is there a way to do this in Java?
    Vijay

    >>
    class LoadExecutable
    static void loadProcess()
    Runtime r = Runtime.getRuntime();
    Process p = r.exex("winword.exe");
    public static void main(String args[])
    loadProcess();
    }Regards
    - ManikantanBoth of these aren't good ideas - neither of them
    deals with the input or output streams at all.
    Everyone who's posted to this thread should read this.
    None of you knows how to use Runtime.exec properly:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-t
    aps.html
    MOD
    Thanks for the tips
    -Regards
    Manikantan

  • How to execute an external executable in my java program?

    hi,
    i want to write a java program to execute some external executables.
    for example, i had an executable which takes a string as its input parameter, and:
    it writes to stdout a string : "[stdout] hello, "+parameter+"!";
    it writes to stderr a string : "[stderr] hello, "+parameter+"!".
    and it exits with an error code 1.
    my java program looks like this:
    public class Test {
      public static void main(String[] args)
      throws Exception {
        String inputParameter = "heavyz";
        String stdoutOutput = null;
        String stderrOutput = null;
        int exitCode;
        // Do something here to launch the executable,
        // providing inputParameter as its input,
        // getting its stdout output to String stdoutOutput,
        // and its stderr output to String stderrOutput,
        // and its exit code to int exitCode.
        return;
    }anybody can help me to complete the program above?
    thanks a lot.
    heavy ZHENG

    check out Runtime.getRuntime().exec();

  • Execute ConcurrentRequest from java program

    In order to execute concurrent request from java program are this 3 lines enough :
    1)ConcurrentRequest concurrentrequest = new ConcurrentRequest(oadbtransaction.getJdbcConnection());
    2)int i = concurrentrequest.submitRequest("some value", " some value", "some value", null, false, vector);
    3)oadbtransaction.commit();
    *******************************8
    I am asking because while executing ConcRequest from PL/SQL I have to call a functin : fnd_global.apps_initialize(user_id ,resp_id, app_id) prior to executing FND_REQUEST.SUBMIT_REQUEST.
    Is there any equivalent in java for apps_initialize?
    thanks in advance.

    hi
    u can call the FND_global using callable statement
    DBTransaction txn = getDBTransaction();
    CallableStatement cs =
    txn.createCallableStatement("begin fnd_global.apps_initialize(:1, :2,:3);end;");
    try
    cs.setString(1, getOADBTransaction().getUserId() );
    cs.setString(2, getOADBTransaction().responsibilityId());
    cs.setString(3, getOADBTransaction().getApplicationID());
    cs.execute();
    cs.close();
    catch (SQLException sqle)
    try { cs.close } catch (Exception(e) {}
    throw OAException.wrapperException(sqle);
    thanx
    Pratap

  • Compiling Java program from other java program

    Hi,
    How can I compile and capture the compilation result from another java program?
    Thanks

    As if I had seen somewhere a hint about being able to
    programatically compile with the help of the class
    sun/tools/javac/Main found in the tools.jar.I saw that article, too, but when I took a look at the JDK's source code, it became apparent that none of the classes in tools.jar are supported. Your program could break with any new version of the JDK.
    If you're still interested, here's the URL:
    http://java.sun.com/developer/JDCTechTips/2003/tt0722.html

  • Executing a .bat/java program every 5 minutes

    Hi,
    I have a java program. I need to run that code every 5 minutes from another java program. could anyone please help me on doing this?
    Thanks!

    while(some condition){
        System.exec(your bat / program)
        Thread.sleep(1000*60*5);
    }

  • Calling an executable from a java program

    How can I call a compiled program from a java program. I have a fortran program, which I would like to call for execution from within my java program. My OS is linux.
    Thanks,
    An

    Not quite sure in the case of fortran program, but one thing can be done, call ur fortran program from a batch (.bat file) and call this .bat file from java ;
    try {
    Process p = Runtime.getRuntime().exec("run.bat");
    p.waitFor();
    catch( Exception e ) {
    }

  • Why do we obtain a java.rmi.MarshalException during a stateless session bean method invocation from a client java program?

    Hello,
    we're using iAS SP3.
    We deployed a stateless session bean that has a business methods with a Vector as argument (put (vector, String)).
    If we call it from a servlet, it works fine. But when we try to call it from a thread, started in a standalone java client program, we obtain a java.rmi.MarshalException.
    We tried to use Vector and HashSet objects as arguments, but we always obtain this kind of exception. It seems strange because a similar
    method that returns a Collection of objects (getAll) works fine. This is the our bean Remote Interface:
    public interface Receive extends EJBObject {
    public void putMessage(Message message, java.lang.String la) throws RemoteException; // it works fine!!!
    public void putMessages(java.util.Vector messages, java.lang.String la) throws RemoteException; // it doesn't work!!!
    Collection getAll (java.lang.String la) throws RemoteException, EJBException; // it works fine!!!!
    This is the java client stack trace:
    java.rmi.MarshalException: CORBA MARSHAL 0 No; nested exception is:
    org.omg.CORBA.MARSHAL: minor code: 0 completed: No
    org.omg.CORBA.MARSHAL: minor code: 0 completed: No
    at java.lang.Class.newInstance0(Native Method)
    at java.lang.Class.newInstance(Class.java:241)
    at com.sun.corba.ee.internal.iiop.ReplyMessage.getSystemException(ReplyMessage.java:93)
    at com.sun.corba.ee.internal.iiop.ClientResponseImpl.getSystemException(ClientResponseImpl.java:82)
    at com.sun.corba.ee.internal.corba.ClientDelegate.invoke(ClientDelegate.java:199)
    at org.omg.CORBA.portable.ObjectImpl._invoke(ObjectImpl.java:248)
    at ejb._Receive_Stub.putMessages(_Receive_Stub.java:731)
    at commlayer.Receiver.run(Receiver.java:67)
    Does anyone know how to solve this problem?
    Thank you in advance,
    Maurizio

    This is big bug!
    This seems to occur when you try to return complex objects (e.g. a vector of classes or even the Date class).
    As a workaround you can add this Ejb or module to the iPlanet Classpath (NT via kregedit, Sun via iasenv skript.).
    This helps but i really don't know why.
    It should be fixed in 6.5, maybe. We'll see.
    Regards

  • Execute Command fron Java Program

    Hi All,
    I am trying to execute a command from Java Application, but iam not getting any result. My problem is:-
    1- Open a terminal.
    2- execute command.
    The same is working fine in windows , the step for windows are:-
    1- execute cmd.exe
    2- go to prompt
    3- execute command.
    How to do it for Solaris 10 ??? Any cmd.exe equivalent for solaris terminal???

    This is done in the exact same way. You open a terminal (depending on your gui its called "console" or "this computer" (CDE), and "Gnome console" (iirc) in the Java desktop) and then you're home free. "javac", "java", etc. should all be in your search path.
    If not look in /usr/java.

  • How to execute mimetex in java program

    hi,
    I am working with an application which has a chat window with a feature of displaying mathematical equation with the help of mimetex. Basically I want to know that how I can call a program like mimetex with some parameter that it takes and find the output for same.
    thanx
    manoj

    You may be able to call WsImport's main() method from your code, something like this:
    import com.sun.tools.ws.WsImport;
    String[] args = {"put", "your", "arguments", "here"};
    WsImport.main(args);(Make sure that the webservices-tools.jar file is on the classpath, since that's the one containing the WsImport.class file - you'll probably need the other webservices jars too).

  • Problem while executing simple java program

    Hi
    while trying to execute a simple java program,i am getting the following exception...
    please help me in this
    java program :import java.util.*;
    import java.util.logging.*;
    public class Jump implements Runnable{
        Hashtable activeQueues = new Hashtable();
        String dbURL, dbuser, dbpasswd, loggerDir;   
        int idleSleep;
        static Logger logger = Logger.getAnonymousLogger();      
        Thread myThread = null;
        JumpQueueManager manager = null;
        private final static String VERSION = "2.92";
          public Jump(String jdbcURL, String user, String pwd, int idleSleep, String logDir) {
            dbURL = jdbcURL;
            dbuser = user;
            dbpasswd = pwd;
            this.idleSleep = idleSleep;
            manager = new JumpQueueManager(dbURL, dbuser, dbpasswd);
            loggerDir = logDir;
            //preparing logger
            prepareLogger();
          private void prepareLogger(){      
            Handler hndl = new pl.com.sony.utils.SimpleLoggerHandler();
            try{
                String logFilePattern = loggerDir + java.io.File.separator + "jumplog%g.log";
                Handler filehndl = new java.util.logging.FileHandler(logFilePattern, JumpConstants.MAX_LOG_SIZE, JumpConstants.MAX_LOG_FILE_NUM);
                filehndl.setEncoding("UTF-8");
                filehndl.setLevel(Level.INFO);
                logger.addHandler(filehndl);
            catch(Exception e){
            logger.setLevel(Level.ALL);
            logger.setUseParentHandlers(false);
            logger.addHandler(hndl);
            logger.setLevel(Level.FINE);
            logger.info("LOGGING FACILITY IS READY !");
          private void processTask(QueueTask task){
            JumpProcessor proc = JumpProcessorGenerator.getProcessor(task);       
            if(proc==null){
                logger.severe("Unknown task type: " + task.getType());           
                return;
            proc.setJumpThread(myThread);
            proc.setLogger(logger);       
            proc.setJumpRef(this);
            task.setProcStart(new java.util.Date());
            setExecution(task, true);       
            new Thread(proc).start();       
         private void processQueue(){       
            //Endles loop for processing tasks from queue       
            QueueTask task = null;
            while(true){
                    try{
                        //null argument means: take first free, no matters which queue
                        do{
                            task = manager.getTask(activeQueues);
                            if(task!=null)
                                processTask(task);               
                        while(task!=null);
                    catch(Exception e){
                        logger.severe(e.getMessage());
                logger.fine("-------->Sleeping for " + idleSleep + " minutes...hzzzzzz (Active queues:"+ activeQueues.size()+")");
                try{
                    if(!myThread.interrupted())
                        myThread.sleep(60*1000*idleSleep);
                catch(InterruptedException e){
                    logger.fine("-------->Wakeing up !!!");
            }//while       
        public void setMyThread(Thread t){
            myThread = t;
        /** This method is only used to start Jump as a separate thread this is
         *usefull to allow jump to access its own thread to sleep wait and synchronize
         *If you just start ProcessQueue from main method it is not possible to
         *use methods like Thread.sleep becouse object is not owner of current thread.
        public void run() {
            processQueue();
        /** This is just another facade to hide database access from another classes*/
        public void updateOraTaskStatus(QueueTask task, boolean success){
            try{         
                manager.updateOraTaskStatus(task, success);
            catch(Exception e){
                logger.severe("Cannot update status of task table for task:" + task.getID() +  "\nReason: " + e.getMessage());       
        /** This is facade to JumpQueueManager method with same name to hide
         *existance of database and SQLExceptions from processor classes
         *Processor class calls this method to execute stored proc and it doesn't
         *take care about any SQL related issues including exceptions
        public void executeStoredProc(String proc) throws Exception{
            try{
                manager.executeStoredProc(proc);
            catch(Exception e){
                //logger.severe("Cannot execute stored procedure:"+ proc + "\nReason: " + e.getMessage());       
                throw e;
         *This method is only to hide QueueManager object from access from JumpProcessors
         *It handles exceptions and datbase connecting/disconnecting and is called from
         *JumpProceesor thread.
        public  void updateTaskStatus(int taskID, int status){       
            try{
                manager.updateTaskStatus(taskID, status);
            catch(Exception e){
                logger.severe("Cannot update status of task: " + taskID + " to " + status + "\nReason: " + e.getMessage());
        public java.sql.Connection getDBConnection(){
            try{
                return manager.getNewConnection();
            catch(Exception e){
                logger.severe("Cannot acquire new database connection: " + e.getMessage());
                return null;
        protected synchronized void setExecution(QueueTask task, boolean active){
            if(active){
                activeQueues.put(new Integer(task.getQueueNum()), JumpConstants.TH_STAT_BUSY);
            else{
                activeQueues.remove(new Integer(task.getQueueNum()));
        public static void main(String[] args){
                 try{
             System.out.println("The length-->"+args.length);
            System.out.println("It's " + new java.util.Date() + " now, have a good time.");
            if(args.length<5){
                System.out.println("More parameters needed:");
                System.out.println("1 - JDBC strign, 2 - DB User, 3 - DB Password, 4 - sleeping time (minutes), 5 - log file dir");
                return;
            Jump jump = new Jump(args[0], args[1], args[2], Integer.parseInt(args[3]), args[4]);
            Thread t1= new Thread(jump);
            jump.setMyThread(t1);      
            t1.start();}
                 catch(Exception e){
                      e.printStackTrace();
    } The exception i am getting is
    java.lang.NoClassDefFoundError: jdbc:oracle:thin:@localhost:1521:xe
    Exception in thread "main" ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
    JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [../../../src/share/back/util.c:820] Please help me.....
    Thanks in advance.....sathya

    I am not willing to wade through the code, but this portion makes me conjecture your using an Oracle connect string instead of a class name.
    java.lang.NoClassDefFoundError: jdbc:oracle:thin:@localhost:1521:xe

  • Batch prog to execute remote java program

    hi all
    i have one batch file which executes the local java program ....
    but i want to execute a java program in a remote machine....
    how do i do this..? kindly help

    Well this is what I do in Windows (I use XP but it works in others):
    First you have to make sure all the class files are in the same folder (duh)
    Then you copy your java.exe from your jre folder into the folder with all your class files.
    Finally, you create a shortcut to java.exe and add your class name to the command line on the shortcut.
    Now all you have to do is double click on the shortcut and your program runs. Sure it's not that pretty but it works.

  • How to execute a java program in linux ternimal shell??

    currently i have write a simple culculation program, i want to know how do i can execute it in LINUX ternimal shell??? rigth now i only can execute it in JAVA program...

    http://java.sun.com/docs/books/tutorial/getStarted/cupojava/unix.html

Maybe you are looking for

  • Why wont my paddle work anymore in my flash catching game?

    Hey guys im making a flash game for a uni project and i had it all working great! I then proceeded to move my code and content onto the second frame to add menus and such to the game and i updated all the code so it should work on the second frame an

  • Can I run two iCloud accounts on my computer

    Okay, so my office decided to link 1 icloud account to all its exsiting macs which will be a lot easier when it comes to purchasing apps to install, reminders, calendars etc. However, my manager wants his personal macbook to be connected to the offic

  • PDF images that magnify when clicked? (but not in Preview)

    I'm viewing a 3-page PDF document received from elsewhere, using Acrobat 7.0 Standard on a MacBook running OS 10.4.11. The document contains 4 figures. When I run the pointer (the "hand") over 2 of these images, a short horizontal bar with a short ar

  • RMI | Firewall  issue revisited

    Hi all, I have searched through these forums for a suitable answer to my problem, but have not gotten any. My RMI client-server app was working perfectly well on a Windows 2000 Advanced Server (with its firewall restrictions), until my company decide

  • Going from Scene 1(jpg) to Scene 2(video)

    I have a jpg of the video on scene 1 and the linked flv file on scene 2. I want to use a play button on scene 1 and when someone clicks on it, it will go to scene 2 and start playing. I also would like scene 2 to have play and stop buttons to replay