Launching a Main Class from a plugin with a launchConfigurationType [message #330573] |
Mon, 04 August 2008 09:02 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: kuglschreibo.hotmail.com
Hello!
I have a plugin which has just a Main class, in ex:
package runner4;
public class Main {
public static void main( String[] args ) {
System.out.println("it works!");
}
}
i would run this main in a external vm. So i implemented the
launchConfigurationDelegate as follows:
public void launch(ILaunchConfiguration configuration, String
mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
monitor.beginTask( "Launching VM...", 3 );
monitor.worked( 1 );
IVMInstall jre = JavaRuntime.getDefaultVMInstall( );
monitor.subTask( "launch..." );
ILaunchManager manager = DebugPlugin.getDefault( ).getLaunchManager( );
ILaunchConfigurationType type = manager.getLaunchConfigurationType(
IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION );
ILaunchConfigurationWorkingCopy workingCopy = type.newInstance( null,
"Start Runner..." );
jre = JavaRuntime.getDefaultVMInstall( );
workingCopy.setAttribute(
IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, jre.getName()
);
workingCopy.setAttribute(
IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH,
jre.getVMInstallType().getId() );
workingCopy.setAttribute(
IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, Main.class.getName(
) );
Bundle bundle = Platform.getBundle( "Runner4" );
StringTokenizer st = new StringTokenizer( bundle.getLocation( ), "/" );
String tmp = null;
while( st.hasMoreElements( ) )
tmp = st.nextToken( );
IPath pluginHome = JavaCore.getClasspathVariable("ECLIPSE_HOME").append(
"plugins" ).append( tmp );
IRuntimeClasspathEntry pluginEntry =
JavaRuntime.newVariableRuntimeClasspathEntry( pluginHome );
pluginEntry.setClasspathProperty( IRuntimeClasspathEntry.USER_CLASSES );
IPath systemLibsPath = new Path( JavaRuntime.JRE_CONTAINER );
IRuntimeClasspathEntry systemLibsEntry =
JavaRuntime.newRuntimeContainerClasspathEntry(
systemLibsPath, IRuntimeClasspathEntry.STANDARD_CLASSES );
List<String> classpath = new ArrayList<String>();
classpath.add( pluginEntry.getMemento() );
classpath.add( systemLibsEntry.getMemento( ) );
workingCopy.setAttribute(
IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath );
workingCopy.setAttribute(
IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false );
monitor.worked(1);
monitor.subTask("launch cont...");
DebugUITools.launch( workingCopy, ILaunchManager.RUN_MODE );
monitor.done( );
}
if i launch this plugin from the run dialog, i get always the
error-message:
java.lang.NoClassDefFoundError: runner4/Main
Caused by: java.lang.ClassNotFoundException: runner4.Main
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
i also tried out the Launching Java Applications Programmatically - code
in the same launchConfigurationDelegate and it worked.
by the way: isn't there another way to get a plugin-classpath?
thanks for your support..
kugl
|
|
|
|
Powered by
FUDForum. Page generated in 0.03194 seconds