I want to write an Java application that displays all name of projects in my workspace. But my program always notices as follows.
Exception in thread "main" java.lang.IllegalStateException: Workspace is closed.
at org.eclipse.core.resources.ResourcesPlugin.getWorkspace(ResourcesPlugin.java:411)
at myPackage.ProjectVisitor.<init>(ProjectVisitor.java:9)
at myPackage.ProjectVisitor.main(ProjectVisitor.java:16)
Here are my steps to create my own application:
Install Java Developement Tool (JDT)
Create a blank eclipse-plugin that satisfying all following options:
- Eclipse version: 3.5 or greater
- Execution environment: JavaSE-1.8
- Is Rich Client Application? (choose NO)
Add .jar named org.eclipse.core.resources_3.10.1.v20150725-1910.jar
Create ProjectVisitor.java as follows.
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; public class ProjectVisitor { public ProjectVisitor() { IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (IProject project : projects) { // do something to display its name } } public static void main(String[] args) { ProjectVisitor m = new ProjectVisitor(); } }
Run as "Java Application".
Please help me. Thanks in advance.