Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert from File to IFile in java, for files outside the project?

Tags:

Normally, this code is used for converting from File to IFile:

IWorkspace workspace= ResourcesPlugin.getWorkspace();     IPath location= Path.fromOSString(file.getAbsolutePath());  IFile ifile= workspace.getRoot().getFileForLocation(location); 

But this only works for java files within the project. How can I get the IFile when File file is not in the workspace (not in the project)?

like image 890
Jenny Smith Avatar asked Jun 06 '09 22:06

Jenny Smith


People also ask

How do I convert files to Ifile?

I am converting using following code. file = ifile. getFullPath(). toFile();

How do you save a project in Java?

Click on your open project in either the Project Explorer or Package Explorer windows. Then File/Copy (or Ctrl-C), then immediately File/Paste (or Ctrl-V). Your'll get a wizard to save the project under a new name. oh my word.


2 Answers

IResource and its child IFile were originally meant to be used only for resources located in the workspace. See the Javadoc for IResource.

However, since Eclipse 3.3 there is support for external files as well, see this Eclipse Wiki page.

like image 121
Zsolt Török Avatar answered Sep 21 '22 08:09

Zsolt Török


I needed this for using the Binding Resolutions from the Eclipse AST framework. But apparently, this is not possible - for anyone who need it, check this site:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=206391

like image 26
Jenny Smith Avatar answered Sep 18 '22 08:09

Jenny Smith