Time for action – creating a headless application

A product hands the runtime off to an application, which can be thought of as a custom Eclipse Runnable class. This is the main entry point to the application, which is responsible for setting up and tearing down the content of the application.

  1. Create a new plug-in, called com.packtpub.e4.headless.application. Ensure that the This plug-in will make contributions to the UI is unselected and Would you like to create a rich client application is set to No:
    Time for action – creating a headless application
  2. Click on Finish and the project will be created.
  3. Open the project, select Plug-in Tools | Open Manifest, and go to the Extensions tab. This is where Eclipse keeps its list of extensions to the system, and where an application is defined.
  4. Click on Add and then type applications into the box. Ensure that the Show only extension points from the required plug-ins is unchecked. Choose the org.eclipse.core.runtime.applications extension point and click on Finish:
    Time for action – creating a headless application
  5. The editor will switch to a tree-based view. Right-click on (application) and choose New | run to create a new application reference:
    Time for action – creating a headless application
  6. Use com.packtpub.e4.headless.application.Application as the class name and click on the underlined class*: link on the left to open a new class wizard, which pre-fills the class name and supplies the IApplication interface:
    Time for action – creating a headless application
  7. Implement the class as follows:
    public class Application implements IApplication {
      public Object start(IApplicationContext c) throws Exception {
        System.out.println("Headless Application");
        return null;
      }
      public void stop() {
      }
    }
  8. Run the application, by going to the Extensions tab of the manifest and clicking on the run button at the top right, or via the Launch an Eclipse application hyperlink. Headless Application will be displayed in the Console view.

What just happened?

Creating an application requires an extension point and a class that implements the IApplication interface. Using the wizard, an application was created and the start method implemented with a simple display message.

When run is clicked, Eclipse will create a new launch configuration which points to an application:

What just happened?

This references the automatically generated ID of the application from the plugin.xml. When Eclipse starts the runtime, it will bring up the runtime environment and then hand runtime control over to the application instance. At the end of the start method's execution, the application will terminate.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.228.35