Launching Java applications programmtically!! [message #216443] |
Mon, 18 June 2007 09:15 |
Jugal Shah Messages: 19 Registered: July 2009 |
Junior Member |
|
|
Hi All,
I am trying to invoke a Java application programmatically from within a
plugin using the approach as mentioned in the Eclipse FAQ "How do I launch
a Java Program?"
http://wiki.eclipse.org/index.php/FAQ_How_do_I_launch_a_Java _program%3F
Following code snippet shows the means I am trying to acheive it:
void launch2(IJavaProject proj, String main) throws CoreException {
try{
IVMInstall vmInstall = JavaRuntime.getVMInstall(proj);
if (vmInstall == null)
vmInstall = JavaRuntime.getDefaultVMInstall();
if (vmInstall != null) {
IVMRunner vmRunner =
vmInstall.getVMRunner(ILaunchManager.RUN_MODE);
if (vmRunner != null) {
String[] classPath = null;
try {
classPath = JavaRuntime.computeDefaultRuntimeClassPath(proj);
} catch (CoreException e) {System.out.println("CoreException");
e.printStackTrace();
} catch(Exception ex){ex.printStackTrace();}
if (classPath != null) {
VMRunnerConfiguration vmConfig =
new VMRunnerConfiguration(main, classPath);
vmConfig.setWorkingDirectory(proj.getProject().getLocation() .toString(
vmConfig.setProgramArguments(new String[]{"-form ",
generatorArgs.getFDLocation(), generatorArgs.getJSPXUserLocation(),
generatorArgs.getJSPOutputLocation(),
generatorArgs.getJavaOutputLocation(),
generatorArgs.getConfigOutputLocation()});
ILaunch launch = new Launch(, ILaunchManager.RUN_MODE, null);
vmRunner.run(vmConfig, launch, null);
}
}
}
}catch(Exception e){
e.printStackTrace();
}
}
The problem here is that, the main class is not getting launched when I am
trying to run using the above method; but when I try to do acheive this by
creating a LauchConfiguration and then launch the application, it works.
Regards,
Jugal Shah
|
|
|
Powered by
FUDForum. Page generated in 0.07373 seconds