如何制作启动特定 Class 的自定义 Eclipse 运行 启动器?
How to make a custom Eclipse run launcher that launches a particular Class?
我正在开发一个eclipse 插件。我想构建一个自定义 运行 启动器,当我针对特定 class 使用它时会执行该启动器。所以场景是,当我 运行 通过 eclipse 运行 时间环境的插件时,我想 运行 一个特定的 class 已经写在这个特定的 eclipse 运行 时间。所以我将使用我的自定义 运行 启动器执行此 class。现在,我不需要任何选项卡或自定义 UI。我只需要在默认 java 控制台中显示特定 class 的输出,而通常输出显示在 eclipse 中。我没有找到这方面的好东西。因为我是新手,所以我越来越困惑。请看看我到目前为止所做的尝试。我没有使用 org.eclipse.debug.core.launchConfigurationTypes 扩展点。在这种情况下,我使用的是 ILaunchShortcut。所以我尝试调用那个特定的 class 并使用下面的代码在 launch 方法中执行它。
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>
我现在应该怎样做才能使这段代码成功运行ning?我需要你的建议和参考。谢谢
根据 greg-449 的评论,我在 plugin.xml 中添加了扩展 org.eclipse.jdt.launching.classpathProviders 并且代码运行良好。
我正在开发一个eclipse 插件。我想构建一个自定义 运行 启动器,当我针对特定 class 使用它时会执行该启动器。所以场景是,当我 运行 通过 eclipse 运行 时间环境的插件时,我想 运行 一个特定的 class 已经写在这个特定的 eclipse 运行 时间。所以我将使用我的自定义 运行 启动器执行此 class。现在,我不需要任何选项卡或自定义 UI。我只需要在默认 java 控制台中显示特定 class 的输出,而通常输出显示在 eclipse 中。我没有找到这方面的好东西。因为我是新手,所以我越来越困惑。请看看我到目前为止所做的尝试。我没有使用 org.eclipse.debug.core.launchConfigurationTypes 扩展点。在这种情况下,我使用的是 ILaunchShortcut。所以我尝试调用那个特定的 class 并使用下面的代码在 launch 方法中执行它。
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>
我现在应该怎样做才能使这段代码成功运行ning?我需要你的建议和参考。谢谢
根据 greg-449 的评论,我在 plugin.xml 中添加了扩展 org.eclipse.jdt.launching.classpathProviders 并且代码运行良好。