Accessing files within a plugin: "Workspace is closed" error [message #443893] |
Mon, 06 February 2006 16:37  |
Eclipse User |
|
|
|
Originally posted by: jkilbour.pol.net
I added a postWindowCreate() method to my
ApplicationWorkbenchWindowAdvisor class to read a file from a directory in
my project, but the "Workspace is closed" exception comes at the very
first line of this:
try{
IWorkspaceRoot myWorkspaceRoot =
ResourcesPlugin.getWorkspace().getRoot();
IProject myProject = myWorkspaceRoot.getProject("Hello");
if (myProject.exists() && !myProject.isOpen())
myProject.open(null);
IFolder dataFolder = myProject.getFolder("datafiles");
if (dataFolder.exists()) {
IFile infile = dataFolder.getFile("infile");
inStream = infile.getContents();
reader = new BufferedReader(new InputStreamReader(inStream));
}
while ((str = reader.readLine()) != null) {
System.out.println(str);
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
|
|
|
|
|
Re: Accessing files within a plugin: "Workspace is closed" error [message #443911 is a reply to message #443899] |
Tue, 07 February 2006 03:41   |
Eclipse User |
|
|
|
Ah, yes, not including it in the class dependency would screw things up a little :-)
If you're running the plugin as a run-time PDE workbench, bear in mind that it has its own workspace (and for good reason; you don't want plugins hosing around with the main workbench whilst you're developing :-)
If you want to get access to an existing project in the runtime-workbench, I suggest that next time you run your plugin, go to the File -> Import -> Existing project into workspace option, then navigate to your original workspace and include the project (which will probably be ../workspace/MyProject if you run with the defaults). Note that this doesn't copy the project; it just brings it into the visibility of your runtime workspace, and has the advantage that anything you change in that project will be visible (after a suitable refresh) in the other.
Bear in mind that when you clean the workspace, this will be lost so you'll have to do it again. This is likely to be an issue if you clean your workspace on each launch (which frankly is probably a good idea, but causes these kind of problems during development :-)
HTH,
Alex.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06359 seconds