java.lang.IllegalStateException: Workspace is closed.

This post belongs to Eclipse JDT Tutorial Series.

This error message starts the whole JDT ASTParser tutorial series.

Exception in thread "main" java.lang.IllegalStateException: Workspace is closed.
at org.eclipse.core.resources.ResourcesPlugin.getWorkspace(
at Main.main(

In brief, this is caused by simply adding dependent jar files to regular java project.

To use JDT, you need to have the program running as a plug-in (or at least, an OSGi-enabled application) rather than using it as a jar.

Step by step tutorials can be found by searching button on the right sidebar:

1. How to create a plug-in project?
2. How JDT works?
3. A complete example to parse a java project.

Category >> Java Development Tools (JDT)  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";
  • Anirban Chatterje

    Can someone please help how to achieve the functionality of call hierarchy by creating a plugin project.
    I want to get eclipse call hierarchy feature via java program.
    Here are some guidance on creation on plugin program ->

    But I would be highly grateful if someone really address my issue.

  • sagar

    I am getting the same exception in my project:

    Exception in thread “main” java.lang.ExceptionInInitializerError
    at ASTModifier.main(
    Caused by: java.lang.IllegalStateException: Workspace is closed.
    at org.eclipse.core.resources.ResourcesPlugin.getWorkspace(
    at org.eclipse.core.filebuffers.FileBuffers.(
    … 1 more
    I am using JDT for creating abstract syntax tree of source java file and then I am modifying the ast using ASTRewrite. Till this it works fine.
    But now I want to reflect changes made by ASTRewrite to be reflected in original source code file, (see link:
    Refer “Write it Down” section.

    As per the above tutorial, I am declaring
    ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();

    Above declaration throws the error. Can you pls tell me what is the reason? Do I have to create a plugin for performing this operation? Is there any other way also?