Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » How to get the project path
How to get the project path [message #492379] Tue, 20 October 2009 06:18 Go to next message
Eclipse UserFriend
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 06:27 Go to previous messageGo to next message
Eclipse UserFriend
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?
Re: How to get the project path [message #492433 is a reply to message #492379] Tue, 20 October 2009 08:32 Go to previous message
Eclipse UserFriend
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: Sun Jul 13 08:35:22 EDT 2025

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

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

Back to the top