Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How can I get the path of the project
How can I get the path of the project [message #519293] Mon, 08 March 2010 12:25 Go to next message
José is currently offline JoséFriend
Messages: 31
Registered: March 2010
Member
Hello, I'm developing a plug-in for Eclipse. I want to save some folders inside the project to use it when it will be published.

The problem is that I don't know how to get the path in will it be the plug-in when it's going to be "installed" on the eclipse. So, how can I get that path?.

For example..the answer I need at get the path in windows would be:

c:\eclipse\plug-ins\myplugin\folderIwanttouse....

or something similar...the problem is that I don't know the first part of the path...

Thank you!
Re: How can I get the path of the project [message #519298 is a reply to message #519293] Mon, 08 March 2010 12:48 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 769
Registered: July 2009
Location: Grenoble, France
Senior Member
You can retrieve the location of a plugin using: Platform.getBundle("myplugin").getLocation()
and you can also get the URL of included folders and resources using: Platform.getBundle("myplugin").findEntries("folder", "*.jpeg", true). Keep in mind that the URL it returns may be bundleresource:// urls, so that you'll probably have to use FileLocator.toFileURL on them.

Regards,
--
Mickael Istria - BonitaSoft S.A.
http://www.bonitasoft.com/products/downloads.php
Re: How can I get the path of the project [message #519524 is a reply to message #519298] Tue, 09 March 2010 08:35 Go to previous messageGo to next message
Luca Gallici is currently offline Luca GalliciFriend
Messages: 2
Registered: January 2010
Junior Member
In my case I had to create a directory Template in the Workspace directory. To do this i use this code:
		
String templateAbsoluteRoot = Platform.getLocation().toOSString() 
			+ PlatformUI.getPreferenceStore().getDefaultString(PreferencesUtils.SEPARATOR)
			+ PlatformUI.getPreferenceStore().getDefaultString(PreferencesUtils.DIR_TEMPLATE);
File templateD = new File(templateAbsoluteRoot); 
		if( ! templateD.exists() )
			templateD.mkdir();

Remember the dependence
org.elcipse.core.resources

in your plugin.xml
Re: How can I get the path of the project [message #519707 is a reply to message #519293] Tue, 09 March 2010 17:48 Go to previous messageGo to next message
José is currently offline JoséFriend
Messages: 31
Registered: March 2010
Member
Hello, thank you so much.

I have tried to use:
Platform.getBundle("myplugin").getLocation()

the problem, is that I don't know how to put like the string of getbundle... I have seen my plugin.xml and I have the id of the plugin...also the name....

I have tried with both and it didn't work...

I must missing something...what?

I also has though about add the dependence that says Luca Gallici on the plugin.xml but I don't know where....in it
Re: How can I get the path of the project [message #519729 is a reply to message #519293] Tue, 09 March 2010 14:28 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

José wrote:
> Hello, I'm developing a plug-in for Eclipse. I want to save some folders
> inside the project to use it when it will be published.

See what Mickael wrote. Bundle#findEntries(*) and Bundle#getEntry(*)
can give you access to folders that are in your plugin. Consider this a
read-only location.

Then the question becomes what to do with them. To copy them out for
use, simply get the InputStream and away you go.

If you are using a legacy API that needs a java.io.File (as opposed to
an InputStream) then use FileLocator.toFileURL(*) to make sure you have
a file that you can use (FileLocator even copies it out to a temporary
location if necessary).

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: How can I get the path of the project [message #520172 is a reply to message #519293] Thu, 11 March 2010 12:59 Go to previous messageGo to next message
José is currently offline JoséFriend
Messages: 31
Registered: March 2010
Member
Thank you Paul Webster, but the problem is that I don't know what to use in:

Platform.getBundle("myplugin").getLocation()

What I must put on the "myplugin" string?

I have tried with the id wizard or name wizard that it's on the plugin.xml, but the execution stops a that time.

I suppose once I have this fixed, I only must use the methods you say to access to the folder I want.

Thank you!
Re: How can I get the path of the project [message #520176 is a reply to message #520172] Thu, 11 March 2010 13:02 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 769
Registered: July 2009
Location: Grenoble, France
Senior Member
José a écrit :
> Thank you Paul Webster, but the problem is that I don't know what to use
> in:
>
> Platform.getBundle("myplugin").getLocation()
>
> What I must put on the "myplugin" string?

You have to put the id of the plugin. It is the value of Bundle-SymbolicName that you can read in your MANIFEST.MF.

--
Mickael Istria - BonitaSoft S.A.
http://www.bonitasoft.com/products/downloads.php
Re: How can I get the path of the project [message #520401 is a reply to message #519293] Fri, 12 March 2010 09:47 Go to previous messageGo to next message
José is currently offline JoséFriend
Messages: 31
Registered: March 2010
Member
A lot of thanks!

It works perfectly. I have seen that the path I get is the path of the myplugin project in the workspace. I suppose that if it's would be installed the path will be indicates the folder of the plugin inside de eclipse folder, won't be?.

[Updated on: Fri, 12 March 2010 09:54]

Report message to a moderator

Re: How can I get the path of the project [message #520541 is a reply to message #520401] Fri, 12 March 2010 14:06 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

José wrote:
> Thanks!
>
> I have seen it, but the problem I'm having is that I'm receiving an
> error at executing this instruction:
>
> Platform.getBundle("myplugin").getLocation()
>
> I suppose the problem is that I'm not putting the correct string where
> it's the "myplugin" one. I have tried with the Id and the Name that are
> in the plugin.xml...

1) it must be the Bundle-SymbolicName (as mentioned by Mickael) from
your MANIFEST.MF file (check in the MANIFEST tab if you have the PDE
editor open). There shouldn't be a relevant ID in your plugin.xml

2) do you run with a workspace? Either a real workspace (because you
use org.eclipse.core.resources), or try simply -data
/path/to/a/temp/workspace

Later,
PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Previous Topic:Running a java program from Plugin Application
Next Topic:Changing the classpath of an exported product
Goto Forum:
  


Current Time: Wed Nov 26 09:14:26 GMT 2014

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

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