views:

126

answers:

2

I'm trying to make an Eclipse launch configuration that I can launch programmatically, kind of building a custom debugger if you like.

I've already got an org.eclipse.debug.core.launchConfigurationTypes extension, as well as .core.launchDelegates, .ui.launchConfigurationTabGroups and .core.sourcePathComputers extensions.

I've got a button that executes the following code:

ILaunchManager mgr = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType lct = mgr.getLaunchConfigurationType(IOpcodeConstants.LAUNCH_CFG_TYPE);
ILaunchConfiguration[] lcs = mgr.getLaunchConfigurations(lct);

for (int i = 0; i < lcs.length; ++i) {
     if (lcs[i].getName().equals("Opcode")) {
         lcs[i].delete();
         break;
     }
}

ILaunchConfigurationWorkingCopy wc = lct.newInstance(null, "Opcode");

Set<String> modes = new HashSet<String>();
modes.add(ILaunchManager.DEBUG_MODE);
wc.setModes(modes);
wc.setPreferredLaunchDelegate(modes, "nz.net.fantail.studio.OpcodeLaunchDelegate");

ILaunchConfiguration lc = wc.doSave();
lc.launch(ILaunchManager.DEBUG_MODE, null);

My launch delegate has the following code:

@Override
public void launch(ILaunchConfiguration configuration, String mode,
        ILaunch launch, IProgressMonitor monitor) throws CoreException {

    ManagementClient client = new ManagementClient("localhost", 6961);

    if (mode.equals(ILaunchManager.DEBUG_MODE)) {
        IDebugTarget target = new OpcodeDebugTarget(launch, client);
        launch.addDebugTarget(target);
    }
}

Everything works perfectly fine until get tries to load the ManagementClient class and throws a NoSuchClassDefException. I suspect this is because it launches in a separate environment from the actual application and as such doesn't have the .jar with the class in its classpath.

Does anyone know how to get around this issue? Cheers!

A: 

What class is it not finding, the ManagementClient or something else? Maybe in your launch configuration you need to set the target classpath yourself.

// customize the classpath
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classPathList);

Here are some other settings that may be useful:

 wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, 
    projectName);
 wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, 
    targetMainClass);
 wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
    programArgs);
 wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, jvmArgs);
Jeremy Raymond
Heh, thanks for that! It's the ManagementClient class that it can't find. I don't seem to have IJavaLaunchConfigurationConstants though - I'll have a look as soon as I can, probably just don't have its plugin in the source path. Cheers!
Fritz H
A: 

Why do you need the button that launches the configuration? If you extend the extension points you mentioned your launch configuration should appear in the debug menu of eclipse ... no need for a seperate button!?

Appart from this I would look after the dependencies of the plugin that contains "ManagementClient". The "NoSuchClassDefException" most often is a result of wrong dependency definitions (maybe the order of the dependencies is wrong [core plugins before ui plugins] ... or your class isn't in an plugin altogether?).

Arne
I'm using a separate button because I haven't actually got or want a menu or toolbar in this particular UI. :-) The plugin that contains ManagementClient is OK on its own though, if I call it from inside the app it works fine - it's only when it's being called by the launch delegate when it fails...
Fritz H