Skip to main content



      Home
Home » Newcomers » Newcomers » Using IFile to get the absolute path of a file in my project
Using IFile to get the absolute path of a file in my project [message #154040] Thu, 25 May 2006 20:42 Go to next message
Eclipse UserFriend
Originally posted by: bswaim.liferay.com

Hi all,

I've been working on this for about 3 hours now, and it's time to ask
for help. I have the following code:

IWorkspace ws = ResourcesPlugin.getWorkspace();

IProject p =
ws.getRoot().getProject("com.liferay.eclipse.myCollPlugin");
IFile f = p.getFile("plugin.xml");
if (f.exists()) {
System.out.print(ws.getRoot());
}

String t = f.getFullPath().toString();

System.out.println(t);

the output of this is /com.liferay.eclipse.myCollPlugin/plugin.xml

I would expect it to be d:/liferay/projects/plugindev/plugin.xml

My goal here is to be able to edit xml files in a specific location in
my project. Do I absolutely have to state the name of the project or
can I just have it grab the currently active project? That's secondary
cuz I can just say your project has to be named x for this to work. My
main issue right now is that I can't figure out how to get access to
the files inside my project without hard coding them to my specific
system which is no good.

Thanks in advance,
Brett
Re: Using IFile to get the absolute path of a file in my project [message #154108 is a reply to message #154040] Fri, 26 May 2006 06:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: matt.querix.com

Hi,

You want the location of the file, use:
file.getLocation()

see:
http://wiki.eclipse.org/index.php/FAQ_What_is_the_difference _between_a_path_and_a_location%3F

Matt

bswaim@liferay.com wrote:
> Hi all,
>
> I've been working on this for about 3 hours now, and it's time to ask
> for help. I have the following code:
>
> IWorkspace ws = ResourcesPlugin.getWorkspace();
>
> IProject p =
> ws.getRoot().getProject("com.liferay.eclipse.myCollPlugin");
> IFile f = p.getFile("plugin.xml");
> if (f.exists()) {
> System.out.print(ws.getRoot());
> }
>
> String t = f.getFullPath().toString();
>
> System.out.println(t);
>
> the output of this is /com.liferay.eclipse.myCollPlugin/plugin.xml
>
> I would expect it to be d:/liferay/projects/plugindev/plugin.xml
>
> My goal here is to be able to edit xml files in a specific location in
> my project. Do I absolutely have to state the name of the project or
> can I just have it grab the currently active project? That's secondary
> cuz I can just say your project has to be named x for this to work. My
> main issue right now is that I can't figure out how to get access to
> the files inside my project without hard coding them to my specific
> system which is no good.
>
> Thanks in advance,
> Brett
Re: Using IFile to get the absolute path of a file in my project [message #154140 is a reply to message #154108] Fri, 26 May 2006 12:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bswaim.liferay.com

Okay, I changed it to this:

IPath path =
ResourcesPlugin.getWorkspace().getRoot().getProject("com.liferay.eclipse.myCollPlugin ").getLocation();

but IPath always comes back as null, why do I have to specify the
project name? Can't I just say use the current project?

Brett

On Fri, 26 May 2006 11:50:08 +0100, Matt Dickie <matt@querix.com>
wrote:

>Hi,
>
>You want the location of the file, use:
>file.getLocation()
>
>see:
> http://wiki.eclipse.org/index.php/FAQ_What_is_the_difference _between_a_path_and_a_location%3F
>
>Matt
>
>bswaim@liferay.com wrote:
>> Hi all,
>>
>> I've been working on this for about 3 hours now, and it's time to ask
>> for help. I have the following code:
>>
>> IWorkspace ws = ResourcesPlugin.getWorkspace();
>>
>> IProject p =
>> ws.getRoot().getProject("com.liferay.eclipse.myCollPlugin");
>> IFile f = p.getFile("plugin.xml");
>> if (f.exists()) {
>> System.out.print(ws.getRoot());
>> }
>>
>> String t = f.getFullPath().toString();
>>
>> System.out.println(t);
>>
>> the output of this is /com.liferay.eclipse.myCollPlugin/plugin.xml
>>
>> I would expect it to be d:/liferay/projects/plugindev/plugin.xml
>>
>> My goal here is to be able to edit xml files in a specific location in
>> my project. Do I absolutely have to state the name of the project or
>> can I just have it grab the currently active project? That's secondary
>> cuz I can just say your project has to be named x for this to work. My
>> main issue right now is that I can't figure out how to get access to
>> the files inside my project without hard coding them to my specific
>> system which is no good.
>>
>> Thanks in advance,
>> Brett
Re: Using IFile to get the absolute path of a file in my project [message #154172 is a reply to message #154040] Fri, 26 May 2006 12:57 Go to previous message
Eclipse UserFriend
Originally posted by: bswaim.liferay.com

OMG, I am so dumb.

I was trying to reference a projec that didn't exist, I forget it put
me in a new workspace... I've wasted two days because I never setup a
project in the first place so there was nothing to reference when the
new eclips env loaded... AAAARRRGGHHH!!!


thanks for your help


On Thu, 25 May 2006 17:42:42 -0700, bswaim@liferay.com wrote:

>Hi all,
>
>I've been working on this for about 3 hours now, and it's time to ask
>for help. I have the following code:
>
>IWorkspace ws = ResourcesPlugin.getWorkspace();
>
> IProject p =
>ws.getRoot().getProject("com.liferay.eclipse.myCollPlugin");
> IFile f = p.getFile("plugin.xml");
> if (f.exists()) {
> System.out.print(ws.getRoot());
> }
>
> String t = f.getFullPath().toString();
>
> System.out.println(t);
>
>the output of this is /com.liferay.eclipse.myCollPlugin/plugin.xml
>
>I would expect it to be d:/liferay/projects/plugindev/plugin.xml
>
>My goal here is to be able to edit xml files in a specific location in
>my project. Do I absolutely have to state the name of the project or
>can I just have it grab the currently active project? That's secondary
>cuz I can just say your project has to be named x for this to work. My
>main issue right now is that I can't figure out how to get access to
>the files inside my project without hard coding them to my specific
>system which is no good.
>
>Thanks in advance,
>Brett
Previous Topic:How to change "Eclipse SDK" in title bar?
Next Topic:Code Hint Dialog -- In a View
Goto Forum:
  


Current Time: Sun Jul 13 18:07:14 EDT 2025

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

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

Back to the top