Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Read a file residing in other plugin
Read a file residing in other plugin [message #1051656] Mon, 29 April 2013 04:27 Go to next message
Ankit Agarwal is currently offline Ankit AgarwalFriend
Messages: 35
Registered: March 2012
Member
I have two plugins say A and B.
In my plugin A i have a file readme.txt. it is inside a folder named docs. So i am reading it inside A plugin using a method as :
public void readFile(){
File file = new File("docs/readme.txt");
}
and everything is fine when i run the test case. but now when i call the same method from Plugin B. On executing it from a test case in B. I am not able to read it as the relative path is no more valid. Then how should read it from Plugin B.
Note : I donot have Activator classes in both of these plugins.

[Updated on: Mon, 29 April 2013 04:37]

Report message to a moderator

Re: Read a file residing in other plugin [message #1051758 is a reply to message #1051656] Mon, 29 April 2013 07:42 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
If you have added org.eclipse.core.runtime to your dependencies, say to plugin B, then, this helps:

Platform.getBundle("A.plugin").getEntry("docs/readme.txt")


Though, this is eclipse/equinox specific and maybe does not work in other OSGi containers.

Ankit Agarwal wrote on Mon, 29 April 2013 06:27
I have two plugins say A and B.
In my plugin A i have a file readme.txt. it is inside a folder named docs. So i am reading it inside A plugin using a method as :
public void readFile(){
File file = new File("docs/readme.txt");
}
and everything is fine when i run the test case. but now when i call the same method from Plugin B. On executing it from a test case in B. I am not able to read it as the relative path is no more valid. Then how should read it from Plugin B.
Note : I donot have Activator classes in both of these plugins.

Re: Read a file residing in other plugin [message #1053296 is a reply to message #1051656] Fri, 03 May 2013 16:30 Go to previous message
Andy McCright is currently offline Andy McCrightFriend
Messages: 2
Registered: April 2010
Junior Member
If you use the getResource(String) API instead of new File(String), then you should be able to access the file from any bundle by using normal import/export semantics.

For example, if bundle A exports the "docs" package and bundle B imports it then you could access it using either Bundle.getResource("docs/readme.txt") or this.getClass().getClassLoader().getResource("docs/readme.txt"). Note that this will return a URL rather than a File object, but you should be able to process it nevertheless.

If you don't want to export the "docs" package/directory, then you could still use the getResource(String) API - but you would need to get a reference to bundle A's Bundle object or classloader.

Hope this helps,
Andy
Previous Topic:Multiple hosts for a single Fragment
Next Topic:Clean Equinox' cache after uninstallation of bundles
Goto Forum:
  


Current Time: Tue Apr 23 07:45:01 GMT 2024

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

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

Back to the top