Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to get the project path
How to get the project path [message #492379] Tue, 20 October 2009 10:18 Go to next message
Rohan  is currently offline Rohan Friend
Messages: 12
Registered: October 2009
Junior Member
I am writing a code for a plugin which will be deployed on other machines. I want to know how do we get the project path so that i can specify the access of any file (eg - an xml or a text file) with respect to this fact.
Presently i make do by writing it as -
File file = new File(System.getProperty("user.dir") + "//ListOfErrors.xml");
But this cant be used later on.
can anyone suggest me a solution to this?
Re: How to get the project path [message #492387 is a reply to message #492379] Tue, 20 October 2009 10:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Rohan,

Comments below.

Rohan wrote:
> I am writing a code for a plugin which will be deployed on other
> machines. I want to know how do we get the project path so that i can
> specify the access of any file (eg - an xml or a text file) with
> respect to this fact.
A project is a development time thing. Generally at runtime you should
expect your plugin to be a jar and it's best not to assume you can
access its contents using java.io.File. You could use basic standard
Java capabilities, such as Class.getResource or
Class.getResourceAsStream, to fetch the resource relative to some class
name, i.e., you put the resource in the same folder as some class and
use that class instance to load it. Within an OSGi environment, URLs of
the form platform:/plugin/<plugin-id>/<path-in-plugin> can be used to
access resources within the plugin. FileLocator.toFileURL can be used if
you absolutely need a java.io.File, but be warned that it's not so
efficient as it will need to unzip your jarred plugin. FileLocator also
has findEntry methods you might want to use.
> Presently i make do by writing it as - File file = new
> File(System.getProperty("user.dir") + "//ListOfErrors.xml");
> But this cant be used later on. can anyone suggest me a solution to this?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to get the project path [message #492433 is a reply to message #492379] Tue, 20 October 2009 12:32 Go to previous message
Ravi  is currently offline Ravi Friend
Messages: 27
Registered: July 2009
Junior Member
Rohan wrote on Tue, 20 October 2009 06:18
I am writing a code for a plugin which will be deployed on other machines. I want to know how do we get the project path so that i can specify the access of any file (eg - an xml or a text file) with respect to this fact.
Presently i make do by writing it as -
File file = new File(System.getProperty("user.dir") + "//ListOfErrors.xml");
But this cant be used later on.
can anyone suggest me a solution to this?



What do you mean by project? Do you mean plugin or the project the user is working on ? IF its plugin, then your query is already answered. If it is latter. IProject.getLocation() should give you the path.
Previous Topic:How to disable renaming of a project programmatically.
Next Topic:Global preferences in 3.5
Goto Forum:
  


Current Time: Thu Apr 25 02:29:34 GMT 2024

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

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

Back to the top