1

How to use IWorkspace ws=ResourcesPlugin.getWorkspace() of Eclipse in a normal Java project?

I want to use Eclipse workspace feting API (IWorkspace), it works perfectly fine when I used this in Plug-in development. But when I write a Java program and use the same code it stop working and throw exception: Exception in thread "main" java.lang.IllegalStateException: Workspace is closed.

public class GitStatusCall {
    public static void main(String[] args) throws IOException, NoHeadException  {
        IWorkspace ws=ResourcesPlugin.getWorkspace();
        System.out.println();
    }
}
howlger
  • 31,050
  • 11
  • 59
  • 99
pooja
  • 11
  • 1
  • Unlike e.g. JGit and the Eclipse compiler for Java (ecj) this is not intended to run outside of Eclipse. So you can't. – howlger Sep 24 '20 at 12:50
  • You can't use this in a normal Java project, it only works in an Eclipse plug-in running in Eclipse. – greg-449 Sep 24 '20 at 14:39
  • The main issue here is that the o.e.c.resources JAR is an OSGi bundle and the ResourcesPlugin class is an Activator for that bundle. The workspace management is tied into the lifecycle of the bundle and requires a running OSGi framework in order to function. This is true also for the dependencies of this bundle (o.e.c.filesystem, o.e.c expressions, o.e.c.runtime). – Patrick Paulin Sep 24 '20 at 18:31
  • Hypothetically, what do you want to do with the workspace? – user253751 Sep 27 '20 at 22:54

1 Answers1

0

ResourcesPlugin.getWorkspace() returns the current Eclipse workspace that Eclipse is working in. But you don't have Eclipse running so that makes no sense. You would have to start up Eclipse. There is probably an easier way to do whatever you are trying to do.

user253751
  • 57,427
  • 7
  • 48
  • 90