Question

I am currently trying to access my eclipse projects by using eclipses workspace and project abstractions, but i failed very soon.

Please have a look at the following code:

public static void main(String[] args) throws Exception {
    String[] equinoxArgs = { "-debug", "-data", "C:\\dev\\build\\workspace" };
    EclipseStarter.startup(equinoxArgs, null);
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    System.out.println(workspace);
}

If i execute it i get:

Exception in thread "main" java.lang.IllegalStateException: Workspace is closed.
    at org.eclipse.core.resources.ResourcesPlugin.getWorkspace(ResourcesPlugin.java:399)
    at de.jaculon.samples.osgi.OsgiSample.main(OsgiSample.java:21)

Does anyone know how to fix this?

Thanks for your help.

Was it helpful?

Solution

EclipseStarter does not initialize the Eclipse workspace.

To run a headless Eclipse application you must define a class that implements org.eclipse.equinox.app.IApplication in a plug-in.

In the plugin.xml you define an application:

<extension
     id="app-id"
     point="org.eclipse.core.runtime.applications">
   <application
        cardinality="singleton-global"
        thread="main"
        visible="true">
     <run
           class="application class">
     </run>
  </application>
</extension>

and you run the application

java -jar plugins/org.eclipse.equinox.launcher_xxx.jar -application application-id -debug -data datapath
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top