Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使自定义Eclipse运行启动器启动特定类?_Eclipse_Eclipse Plugin_Eclipse Rcp - Fatal编程技术网

如何使自定义Eclipse运行启动器启动特定类?

如何使自定义Eclipse运行启动器启动特定类?,eclipse,eclipse-plugin,eclipse-rcp,Eclipse,Eclipse Plugin,Eclipse Rcp,我正在开发一个eclipse插件。我想构建一个自定义运行启动器,当我对特定类使用它时,它将被执行。因此,场景是,当我通过eclipse运行时环境运行插件时,我想运行一个已经在这个特定eclipse运行时编写的特定类。因此,我将使用我的自定义运行启动器执行这个类。目前,我不需要任何选项卡或自定义UI。我只需要在默认java控制台中显示该特定类的输出,在eclipse中通常会显示这些输出。在这方面我没有发现什么好东西。因为我是新来的,所以我比较困惑。请看一下到目前为止我都试了些什么。我没有使用org

我正在开发一个eclipse插件。我想构建一个自定义运行启动器,当我对特定类使用它时,它将被执行。因此,场景是,当我通过eclipse运行时环境运行插件时,我想运行一个已经在这个特定eclipse运行时编写的特定类。因此,我将使用我的自定义运行启动器执行这个类。目前,我不需要任何选项卡或自定义UI。我只需要在默认java控制台中显示该特定类的输出,在eclipse中通常会显示这些输出。在这方面我没有发现什么好东西。因为我是新来的,所以我比较困惑。请看一下到目前为止我都试了些什么。我没有使用org.eclipse.debug.core.launchConfigurationTypes扩展点。相反,在本例中,我使用的是快捷方式。因此,我尝试调用该特定类,并使用下面的代码在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>


我现在应该怎么做才能使这段代码成功运行?我需要你的建议和推荐信。谢谢。

根据我的评论,我在plugin.xml中添加了扩展名org.eclipse.jdt.launching.classpathProviders,代码工作得很好。

IJavaLaunchConfigurationConstants
位于
org.eclipse.jdt.launching
插件中,因此您需要将其包含在插件的依赖项中。谢谢照你说的做。