Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Platform - User Assistance (UA) » File Path Problem in Plugin Development
File Path Problem in Plugin Development [message #522015] Fri, 19 March 2010 16:07 Go to next message
Yu Sun is currently offline Yu SunFriend
Messages: 58
Registered: July 2009
Member
Hi everyone,

I am having the problem of getting the path of certain file in a plugin development.

In the initial Eclipse, I created the plugin project - PluginA:

PluginA
- AcitonHandler.java
- file1
- file2

What I want to do now is that I want to access the file1 and file2 in AcitonHandler.java. However, I do not know how to get the relative path of the PluginA folder.

I checked some of the messages, but most of them are about getting the path in the runtime-eclipse environment, not the parent Eclipse environment. Therefore, the desired result is that when ActionHandler.java is triggered in the runtime-Eclipse, it can access the file1 and file2 in the parent Eclipse folder.

Thanks a lot.

Yu
Re: File Path Problem in Plugin Development [message #522702 is a reply to message #522015] Tue, 23 March 2010 16:25 Go to previous message
Chris Goldthorpe is currently offline Chris GoldthorpeFriend
Messages: 815
Registered: July 2009
Senior Member
Yu Sun wrote on Fri, 19 March 2010 12:07
Hi everyone,

I am having the problem of getting the path of certain file in a plugin development.

In the initial Eclipse, I created the plugin project - PluginA:

PluginA
- AcitonHandler.java
- file1
- file2

What I want to do now is that I want to access the file1 and file2 in AcitonHandler.java. However, I do not know how to get the relative path of the PluginA folder.

I checked some of the messages, but most of them are about getting the path in the runtime-eclipse environment, not the parent Eclipse environment. Therefore, the desired result is that when ActionHandler.java is triggered in the runtime-Eclipse, it can access the file1 and file2 in the parent Eclipse folder.

Thanks a lot.

Yu


You need to use the class org.eclipse.core.runtime.FileLocator., the reason being that it knows how to read files within jar files, and if your plug-ins are jarred this is the only way to read the contents.

Here is a typical sequence:

Bundle bundle = Platform.getBundle(pluginId);
URL contentURL = FileLocator.find(bundle, new Path(path), null);

// call openStream() from the URL to get an input stream
Previous Topic:Welcome Page in language other than English
Next Topic:adding infocenters to search scope : works in 3.5 broken in in 3.4 ?
Goto Forum:
  


Current Time: Tue Dec 10 21:22:50 GMT 2024

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

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

Back to the top