Accessing files within a plugin: "Workspace is closed" error [message #443893] |
Mon, 06 February 2006 21: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 #443899 is a reply to message #443897] |
Mon, 06 February 2006 22:35 |
Eclipse User |
|
|
|
Originally posted by: jkilbour.pol.net
I found that I was including the plugin jar in the classpath but not
including it as a plugin dependency. Fixing that solved the "Workspace
closed" bit.
However, I cannot reference the project to get to the file, as the project
does not exist. The following prints "0" to the console:
IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IProject[] projects = myWorkspaceRoot.getProjects();
System.out.println(projects.length);
|
|
|
Re: Accessing files within a plugin: "Workspace is closed" error [message #443911 is a reply to message #443899] |
Tue, 07 February 2006 08:41 |
Alex Blewitt Messages: 946 Registered: July 2009 |
Senior Member |
|
|
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.
|
|
|
Re: Accessing files within a plugin: "Workspace is closed" error [message #444024 is a reply to message #443911] |
Wed, 08 February 2006 14:46 |
Eclipse User |
|
|
|
Originally posted by: jkilbour.pol.net
Alex Blewitt wrote:
> 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.
Can this be done programmatically? I am making an RCP, right now based on
the most basic hello world RCP, and so my plugin has no menu or workspace
options.
Thanks.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03169 seconds