Search code examples
javaeclipseprogram-entry-pointequinox

eclipse equinox: how to set return value?


How to set the return value of a Java application started via Eclipse Equinox? It implements IApplication. I see that the start() method has an argument of type IApplicationContext, which provides a setResultValue() method. But this value is an Object, not an Integer. I searched the Internet for an example of its use but could not find one.

What would happen if our application simply calles exit()?

In my current understanding, the return value of a Java application is either the argument of exit(), if that is called, or else the return value of main(). This return value is available after the application exits, which happens either if exit() is called or else if tha application's last thread terminates.

Our application is started from within Eclipse and as standalone tool (in GUI and batch mode).


Solution

  • The normal way of doing this is the return value of the IApplication start method:

    @Override
    public Object start(IApplicationContext context)
    {
       ... run the application
    
      return Integer.valueOf(0);
    }
    

    Although the return value can be any Object it is usual to return an Integer.

    The IApplication object already defines a few exit values for your EXIT_OK, EXIT_RESTART and EXIT_RELAUCH:

    public static final Integer EXIT_OK = new Integer(0);
    
    public static final Integer EXIT_RESTART = new Integer(23);
    
    public static final Integer EXIT_RELAUNCH = new Integer(24);