Search code examples
eclipseeclipse-plugineclipse-rcp

How to make a custom Eclipse run launcher that launches a particular Class?


I am developing an eclipse plugin. I want to build a custom run launcher that would be executed when i use it against a specific class. So the scenario is, when i run the plugin via eclipse run time environment i want to run a particular class which is already written in this particular eclipse run time. So i will execute this class with my custom run launcher. For now, i do not need any tab or custom UI. I just need to show the output of that particular class in default java console where normally outputs are shown in eclipse. I did not find great stuff in this regard. As i am new so i am rather getting confused more. Please have a look on what i have tried so far. I am not using org.eclipse.debug.core.launchConfigurationTypes extension point. Rather i am using ILaunchShortcut in this case. So i tried to call that particular class and execute it in launch method using the below code.

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

But here the problem is i am not able to resolve IJavaLaunchConfigurationConstants in my code anyway. So i am fully stuck here. See my plugin.xml file also for your convenience.

    <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>

What should i do now to make this code successfully running? I need your suggestions and references. Thanks.


Solution

  • As per comment of greg-449 i added following the extension org.eclipse.jdt.launching.classpathProviders in the plugin.xml and the code worked perfectly.