How to create an Eclipse debugging launcher that launches a class

I am trying to create an Eclipse launch configuration that I can run programmatically, sort of like creating a custom debugger if you want.

I already have an extension org.eclipse.debug.core.launchConfigurationTypes, as well as extensions .core.launchDelegates, .ui.launchConfigurationTabGroupsand .core.sourcePathComputers.

I have 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 fine until it tries to load the ManagementClient class and throws a NoSuchClassDefException. I suspect this is because it runs in a separate environment from a real application and as such does not have a .jar with a class in its classpath.

Does anyone know how to get around this problem? Hurrah!

+3
2

, ManagementClient - ? , .

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

, :

 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);
+1

, ? , eclipse... !?

Appart , "ManagementClient". "NoSuchClassDefException" (, [ ui]... ?).

0

Source: https://habr.com/ru/post/1724898/


All Articles