Time for action – launching Eclipse from within Eclipse
Eclipse can launch a new Eclipse application by clicking on the run icon, or via the Run menu.
- Select the plug-in project in the workspace.
- Click on the run icon to launch the project. The first time this happens, a dialog will be shown; subsequent launches will remember the chosen type:
- Choose the Eclipse Application type and click on OK. A new Eclipse instance will be launched.
- Close the Welcome page in the launched application, if shown.
- Click on the hello world icon in the menu bar, or navigate to Sample Menu | Sample Command from the menu, and the dialog box created via the wizard will be shown:
- Quit the target Eclipse instance by closing the window, or via the usual keyboard shortcuts or menus (Cmd + Q on macOS or Alt + F4 on Windows).
What just happened?
Upon clicking on run in the toolbar (or via Run | Run As | Eclipse Application) a launch configuration is created, which includes any plug-ins open in the workspace. A second copy of Eclipse—with its own temporary workspace—will enable the plug-in to be tested and verify that it works as expected.
The run operation is intelligent, in that it launches an application based on what is selected in the workspace. If a plug-in is selected, it will offer the opportunity to run as an Eclipse Application; if a Java project with a class with a main
method, it will run it as a standard Java Application; and if it has tests, then it will offer to run the test launcher instead.
However, the run operation can also be counter-intuitive; if clicked a second time, and in a different project context, then something other than the expected launched might be run.
A list of the available launch configurations can be seen by going to the Run menu, or by going to the dropdown to the right of the run icon. The Run | Run Configurations menu shows all the available types, including any previously run:
By default, the runtime workspace is kept between runs. The launch configuration for an Eclipse application has options that can be customized; in the preceding screenshot, the Workspace Data section in the Main tab shows where the runtime workspace is stored, and an option is shown that allows the workspace to be cleared (with or without confirmation) between runs.
Launch configurations can be deleted by clicking on the red delete icon on the top left, and new launch configurations can be created by clicking on the new icon. Each launch configuration has a type:
- Eclipse Application
- Java Applet
- Java Application
- JUnit
- JUnit Plug-in Test
- OSGi Framework
The launch configuration can be thought of as a pre-canned script that can launch different types of programs. Additional tabs are used to customize the launch, such as the environment variables, system properties, or command-line arguments. The type of the launch configuration specifies what parameters are required and how the launch is executed.
When a program is launched with the run icon, changes to the project's source code while it is running have no effect. However, as we'll see in the next section, if launched with the debug icon, changes can take effect.
If the target Eclipse is hanging or otherwise unresponsive, in the host Eclipse instance, the Console view (shown by navigating to Window | View | Show View | Other | General | Console menu) can be used to stop the target Eclipse instance.
Pop quiz: launching Eclipse
Q1. What are the two ways of terminating a launched Eclipse instance?
Q2. What are launch configurations?
Q3. How are launch configurations created and deleted?
Have a go hero – modifying the plug-in
Now that the Eclipse plug-in is running, try the following:
- Change the message of the label and title of the dialog box to something else
- Invoke the action by using the keyboard shortcut (defined in
plugin.xml
) - Change the tooltip of the action to a different message
- Switch the action icon to a different graphic (if a different filename is used, remember to update it in
plugin.xml
andbuild.properties
)