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
- There should not be any other UI elements loaded
- 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).
- 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
- 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.
- 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).
- We need to add the E4 application model to our project like we do with any other E4 development.
- 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).