Monday 13 April 2015

Eclipse 4 (E4) : Creating Eclipse RCP Headless (Command line) Application



Simple way to create RCP Headless application is to define Trimmed window in the application model and making it as non visible / non to be rendered.

If made non visible, there will be no window launched and application will continue to run in the background. Only way to close application is to kill (If you don't run it with -consoleLog).

If made not to be rendered, application will run the code and simply exits. Be careful to use event based mechanisms in this case as application may not wait till the time event is received.

Though we do the above points, creating a pure Eclipse E4 based RCP headless (command line) application is not possible without modifying/adding to the Eclipse framework. This I conclude after serching in the Internet (Google, Stackoverflow) and conversing with Vogella,

Reasons are
  1. Eclipse E4 model is basically for UI applications. All the elements that you find in the model are for UI.
  2. Binding context, Part, PartStack, Trimmed windows, Controls - Everything is for UI.
  3. If Trimmed windows are not defined, Eclipse framework throws exception and exits. 
Another reason why it is not pure command line application is that, we can see that model defining plugins depend on e4.ui plugins which are part of the framework.

The general requirements of a console / headless/ command line application are
  1. There should not be any other UI elements loaded
  2. In some cases, the requirement is that the application should be able to take the user input via the console / command line and prints the output to the same console (Logging).
  3. Application should be able to have a nicer termination mechanism (either by closing the command line shell that opened the application, by pressing CTRL + C, CTRL + /, CTRL + D, CTRL + Q etc) instead of killing it.
With Eclipse E4, out of the above requirements, first one is achievable. Second and third are partially achievable (provided one develops the application without changes to the E4 framework).

Ok, so how do we develop an E4 based console application 
  1. We need to have a product defining plugin, defining a product. We will have to use this product in our product configuration file. This is irrespective of whether we have normal eclipse application or E4 based one. We anyhow need to mention the startup plugin by this way.
  2. Once we define the product, next step is to either to use the default E4 application, org.eclipse.e4.ui.workbench.swt.E4application or to define our own application (by defining extension point org.eclipse.core.runtime.applications, but here you need to define Application, ApplicationWorkBenchAdvisor and call PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); This is because, E4 model is loaded only when work bench is created. This is also reason that we never can build a pure console only application using Eclipse E4).
  3. We need to add the E4 application model to our project like we do with any other E4 development.
  4. In the application model, we define a trimmed window and we have to simply make it invisible (to make the application run in the background, in this case, add -consoleLog while running the application) or not to be rendered (to make the application exit after finishing the job, in this case usage of event mechanism have to be carefully handled).
Logging: 

Inside Eclipse IDE, we have the standard console window that will print whatever the code prints to stdout. But when we build the product using maven-tycho or PDE, we have to ensure that we are making the product build based on java.exe instead of javaw.exe (the eclipse.exe is based on javaw.exe). The reason is that javaw.exe has no console. i.e. stdout in javaw.exe is set to null.

While tycho has its own builder to build based on eclipse.exe, PDE build has options to set java.exe as the base for product build (I am not sure how to do that though)

There is a eclipsec.exe which is also based on javaw.exe but has a console. But you cannot by default do the branding in the product configuration file. May be launch4j can be used to brand the eclipsec.exe according to project needs. Also note that eclipsec.exe is only for Windows platform.

But while using javaw.exe (eclipse.exe), the option -consoleLog when passed will open the new console. We can get the output to the new console but not to the same console. Still figuring out how to output to the same console).

No comments:

Post a Comment

Gallery

Object Oritented, Git

Most Commented

OOAD

Contact Form

Name

Email *

Message *

2014 © Planer - Responsive Blogger Magazine Theme
Planer theme by Way2themes