简体   繁体   English

如何制作一个启动Class的Eclipse调试启动器

[英]How to make an Eclipse debug launcher that launches a Class

I'm trying to make an Eclipse launch configuration that I can launch programmatically, kind of building a custom debugger if you like. 我正在尝试创建一个可以以编程方式启动的Eclipse启动配置,如果您愿意,可以构建一个自定义调试器。

I've already got an org.eclipse.debug.core.launchConfigurationTypes extension, as well as .core.launchDelegates , .ui.launchConfigurationTabGroups and .core.sourcePathComputers extensions. 我已经有了一个org.eclipse.debug.core.launchConfigurationTypes扩展,以及.core.launchDelegates.ui.launchConfigurationTabGroups.core.sourcePathComputers扩展。

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. 一切正常,直到尝试加载ManagementClient类并抛出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. 我怀疑这是因为它在与实际应用程序不同的环境中启动,因此在类路径中没有类.jar。

Does anyone know how to get around this issue? 有谁知道如何解决这个问题? Cheers! 干杯!

What class is it not finding, the ManagementClient or something else? 它找不到什么类,ManagementClient还是其他什么? 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);

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!? 如果你扩展你提到的扩展点你的启动配置应该出现在eclipse的调试菜单中......不需要一个单独的按钮!?

Appart from this I would look after the dependencies of the plugin that contains "ManagementClient". 从这个公寓我将照顾包含“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?). “NoSuchClassDefException”通常是错误的依赖关系定义的结果(可能依赖关系的顺序是错误的[ui插件之前的核心插件] ......或者你的类完全不在插件中?)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM