Search code examples
javajarruntimeprogram-entry-point

How can I run a java program from a java program?


I would like to write a java program that can run an another java programs Main class in runtime. How can I do that?


Solution

  • read this.

    Basically you run new process and execute

    Process tr = Runtime.getRuntime().exec( new String[]{ "XXX" } );
    

    where XXX is phrase just like you would type in commandline. Remember that program might be in different location than your current execution so you might have to type command like java \path\to\program\program or such.