Skip to main content

Can Java execute a .java file outside of current JVM in separate java prog.

2 replies [Last post]
sonal_agg
Offline
Joined: 2008-01-02

Can Java execute a .java file outside of current JVM in separate java program ??
Like we can compile a code from wihin a java file by using the following :

Tool javac = ToolProvider.getSystemJavaCompiler();

Similarly,can we execute i.e. run a java program from within a java file i.e. running d java command from within the java file ??If yes then please tell me how??

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
horunkoya
Offline
Joined: 2008-01-08

[code]
File sourceFile1 = new File(...);
File sourceFile2 = new File(...);
int result = com.sun.tools.javac.Main.compile(new String[] {
sourceFile1.getAbsolutePath(),
sourceFile2.getAbsolutePath()
},
new PrintWriter(System.err)));
[/code]

sonal_agg
Offline
Joined: 2008-01-02

The solution told by you is a code for compiling a program but i want to run i.e. execute a program from a diffrent program i.e. execute " java Hello " command from some other program.