Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Access Files in Plugin
Access Files in Plugin [message #857005] Thu, 26 April 2012 06:53 Go to next message
Alok Mishra is currently offline Alok MishraFriend
Messages: 16
Registered: April 2012
Junior Member
Hi,

I'm working on a plugin for eclipse. I want to keep some configuration files in the plugin and at runtime access them. Please help how can I access a file included in the plugin.

Thank You.
-Alok
Re: Access Files in Plugin [message #857281 is a reply to message #857005] Thu, 26 April 2012 12:14 Go to previous messageGo to next message
Eclipse UserFriend
Hi Alok

The class org.eclipse.core.runtime.FileLocator might solve your issues. Have a look at the JavaDoc and ask for any additional help.

-Andreas
Re: Access Files in Plugin [message #858485 is a reply to message #857281] Fri, 27 April 2012 06:36 Go to previous messageGo to next message
Alok Mishra is currently offline Alok MishraFriend
Messages: 16
Registered: April 2012
Junior Member
Thanks for the help Andreas. The following code resolved my problem partially:

	Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileURL = bundle.getEntry("data/Sample.data");
	File file = new File(FileLocator.resolve(fileURL).toURI().getPath());

But this code works only in Linux when I extract the jar file into the eclipse plugin directory. The same code fails to work on a Windows system giving the Null Pointer Exception for the file. The file is definitely present in the eclipse plugin directory for Windows as well.

Am I missing something here.

Thank You.
-Alok
Re: Access Files in Plugin [message #859492 is a reply to message #858485] Fri, 27 April 2012 17:05 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4430
Registered: July 2009
Senior Member

Do you need really it to be a file? You could just read the contents from the URL, then it wouldn't matter whether it's in a .jar or not.

_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Access Files in Plugin [message #868748 is a reply to message #859492] Wed, 02 May 2012 13:41 Go to previous message
Alok Mishra is currently offline Alok MishraFriend
Messages: 16
Registered: April 2012
Junior Member
No Nitin. I need it to be a file (for that matter a resource to be added with the plugin) and not a URL. Currently extracting the jar in the plugin directory is working in Linux, but the same code fails in Windows.
Previous Topic:Problem between mac and Windows
Next Topic:Accessing IProject through IFolder/IFile in plugin
Goto Forum:
  


Current Time: Fri Mar 29 04:48:22 GMT 2024

Powered by FUDForum. Page generated in 0.04811 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top