You should use the org.eclipse.equinox.app.IApplication
interface, which gives you ability to return a result from the start()
method, which is then returned as exit code from the Java process. In case you don't want to use this API, the following code, shows how Equinox itself controls the exit code of the Java process:
import org.eclipse.osgi.service.environment.EnvironmentInfo;
private static EnvironmentInfo getEnvironmentInfo() {
BundleContext bc = Activator.getContext();
if (bc == null)
return null;
ServiceReference infoRef = bc.getServiceReference(EnvironmentInfo.class.getName());
if (infoRef == null)
return null;
EnvironmentInfo envInfo = (EnvironmentInfo) bc.getService(infoRef);
if (envInfo == null)
return null;
bc.ungetService(infoRef);
return envInfo;
}
public static void setExitCode(int exitCode) {
String key = "eclipse.exitcode";
String value = Integer.toString(exitCode); // the exit code
EnvironmentInfo envInfo = getEnvironmentInfo();
if (envInfo != null)
envInfo.setProperty(key, value);
else
System.getProperties().setProperty(key, value);
}
The code above is not taken one for one, but it gives the idea.