Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Launching a Main Class from a plugin with a launchConfigurationType
Launching a Main Class from a plugin with a launchConfigurationType [message #330573] Mon, 04 August 2008 09:02 Go to next message
Eclipse UserFriend
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
Re: Launching a Main Class from a plugin with a launchConfigurationType [message #330574 is a reply to message #330573] Mon, 04 August 2008 09:24 Go to previous message
Eclipse UserFriend
Originally posted by: kuglschreibo.hotmail.com

Sorry, i didn't recognize that this is the wrong newsgroup - i will post
it again on tools.jdt..
Previous Topic:Update doesn't work - 3.4
Next Topic:ComboBoxCellEditor doesn't fireApplyEditorValue()
Goto Forum:
  


Current Time: Fri Dec 27 06:45:11 GMT 2024

Powered by FUDForum. Page generated in 0.03560 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top