我正在开发一个eclipse插件。我想构建一个自定义运行启动器,当我针对特定类使用它时将执行该启动器。所以场景是,当我通过 eclipse 运行时环境运行插件时,我想运行一个特定的类,该类已经在这个特定的 eclipse 运行时中编写。所以我将使用我的自定义运行启动器执行这个类。目前,我不需要任何选项卡或自定义 UI。我只需要在默认的 java 控制台中显示该特定类的输出,其中通常在 eclipse 中显示输出。我没有找到这方面的好东西。因为我是新手,所以我更困惑了。请看看我到目前为止尝试过的内容。我没有使用org.eclipse.debug.core.launchConfigurationTypes扩展点。相反,我正在使用ILaunchShortcut在这种情况下。所以我尝试调用该特定类并使用以下代码在启动方法中执行它。
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType type = manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
ILaunchConfigurationWorkingCopy wc = type.newInstance(null, "SampleConfig");
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "Test");
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "Test1");
ILaunchConfiguration config = wc.doSave();
config.launch(ILaunchManager.RUN_MODE, null);
但这里的问题是我无论如何都无法在我的代码中解决IJavaLaunchConfigurationConstants问题。所以我完全被困在这里。为方便起见,另请参阅我的 plugin.xml 文件。
<plugin>
<extension
point="org.eclipse.debug.ui.launchShortcuts">
<shortcut
class="launcher.LaunchShortcut"
id="launcher.shortcut2"
label="Launcher Test"
modes="run">
<contextualLaunch>
<contextLabel mode="run" label="Run Launcher" />
<enablement>
<with
variable="selection">
<count
value="1">
</count>
<iterate>
<adapt type="org.eclipse.core.resources.IResource">
<and>
<test property="org.eclipse.core.resources.name" value="Test1.java"/>
</and>
</adapt>
</iterate>
</with>
</enablement>
</contextualLaunch>
</shortcut>
</extension>
</plugin>
我现在应该怎么做才能使此代码成功运行?我需要你的建议和参考。谢谢。
根据greg-449 的评论,我在 plugin.xml 中添加了扩展org.eclipse.jdt.launching.classpathProviders并且代码运行良好。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句