Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to get current project's name and path
How to get current project's name and path [message #322730] Tue, 27 November 2007 15:48 Go to next message
Eclipse UserFriend
Originally posted by: noyanculum.yahoo.com

Hello all,

I'm writing a plugin for Eclipse and since somedays i'm searching how to
get current project's name and full path (i.e.
C:\...\workspace\projectname).

I've read all articles and all emails and i tried all codes given but
unfortunately no success no success.

Please kindly can anyone give me a working solution. I think i need
dependencies, import declerations lines and codeline.

Any help will be really very very appreciated.

Thanx in advance.

Best Regards,
Ran
Re: How to get current project's name and path [message #322731 is a reply to message #322730] Tue, 27 November 2007 16:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Ran,

IResource.getLocation()/getLocationURI() should do the trick.


Noyan Culum wrote:
> Hello all,
>
> I'm writing a plugin for Eclipse and since somedays i'm searching how
> to get current project's name and full path (i.e.
> C:\...\workspace\projectname).
>
> I've read all articles and all emails and i tried all codes given but
> unfortunately no success no success.
> Please kindly can anyone give me a working solution. I think i need
> dependencies, import declerations lines and codeline.
>
> Any help will be really very very appreciated.
>
> Thanx in advance.
>
> Best Regards,
> Ran
>
>
Re: How to get current project's name and path [message #322732 is a reply to message #322731] Tue, 27 November 2007 17:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: noyanculum.yahoo.com

Ed,

Thank you but org.eclipse.core.resources.IResource don't have
getLocation() method.

I tried also
org.eclipse.core.resources.Resourcesplugin.getWorkspace().ge tRoot().getLocation()
but this give this path:
"C:\...\My Documents\runtime-EclipseApplication".

But I'm searching how to get this path:
"C:\...\My Documents\workspace".

+ additionally i'm searching how to get projectname.
Re: How to get current project's name and path [message #322735 is a reply to message #322732] Tue, 27 November 2007 18:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------080301000708020704090502
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Noyan.

You mustn't be looking properly
< http://help.eclipse.org/help33/topic/org.eclipse.platform.do c.isv/reference/api/org/eclipse/core/resources/IResource.htm l#getLocation%28%29>


http://help.eclipse.org/help33/topic/org.eclipse.platform.do c.isv/reference/api/org/eclipse/core/resources/IResource.htm l#getLocation()
< http://help.eclipse.org/help33/topic/org.eclipse.platform.do c.isv/reference/api/org/eclipse/core/resources/IResource.htm l#getLocation%28%29>

The getName method is in that API as well.


Noyan wrote:
> Ed,
>
> Thank you but org.eclipse.core.resources.IResource don't have
> getLocation() method.
>
> I tried also
> org.eclipse.core.resources.Resourcesplugin.getWorkspace().ge tRoot().getLocation()
> but this give this path:
> "C:\...\My Documents\runtime-EclipseApplication".
>
> But I'm searching how to get this path:
> "C:\...\My Documents\workspace".
>
> + additionally i'm searching how to get projectname.
>
>
>


--------------080301000708020704090502
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Noyan.<br>
<br>
You mustn't be looking properly<a
href=" http://help.eclipse.org/help33/topic/org.eclipse.platform.do c.isv/reference/api/org/eclipse/core/resources/IResource.htm l#getLocation%28%29"><br>
</a>
<blockquote><a
href=" http://help.eclipse.org/help33/topic/org.eclipse.platform.do c.isv/reference/api/org/eclipse/core/resources/IResource.htm l#getLocation%28%29"> http://help.eclipse.org/help33/topic/org.eclipse.platform.do c.isv/reference/api/org/eclipse/core/resources/IResource.htm l#getLocation()</a><br>
</blockquote>
The getName method is in that API as well.<br>
<br>
<br>
Noyan wrote:
<blockquote
cite="mid:e59b1ae69f58802a612d53455e7c78f8$1@www.eclipse.org"
type="cite">Ed,
<br>
<br>
Thank you but org.eclipse.core.resources.IResource don't have
getLocation() method.
<br>
<br>
I tried also
org.eclipse.core.resources.Resourcesplugin.getWorkspace().ge tRoot().getLocation()
but this give this path:
<br>
"C:\...\My Documents\runtime-EclipseApplication".
<br>
<br>
But I'm searching how to get this path:
<br>
"C:\...\My Documents\workspace".
<br>
<br>
+ additionally i'm searching how to get projectname.
<br>
<br>
<br>
<br>
</blockquote>
<br>
</body>
</html>

--------------080301000708020704090502--
Re: How to get current project's name and path [message #322744 is a reply to message #322735] Tue, 27 November 2007 21:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: noyanculum.yahoo.com

Dear Ed,

I saw, yes you have reason, there is getLocation() method here. Than i
tried different uses with this, for example:

org.eclipse.core.resources.IResource iresource;
System.out.println(iresource.getLocation());


But this returns a null response, so unfortunately, i can't find the exact
code solution with this (and others) suggestion. If you (or anotherone)
can kindly give me a working codeline, it will be really very appreciated.

Thanx again.
Ran
Re: How to get current project's name and path [message #322746 is a reply to message #322744] Tue, 27 November 2007 22:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Noyan,

Perhaps the resource doesn't actually exist or something else is wrong?
The getLocationURI is more general, you might try that. If these are
both returning null there's likely something going on you've not told us
about.


Noyan wrote:
> Dear Ed,
>
> I saw, yes you have reason, there is getLocation() method here. Than i
> tried different uses with this, for example:
>
>
> org.eclipse.core.resources.IResource iresource;
> System.out.println(iresource.getLocation());
> 

>
> But this returns a null response, so unfortunately, i can't find the
> exact code solution with this (and others) suggestion. If you (or
> anotherone) can kindly give me a working codeline, it will be really
> very appreciated.
>
> Thanx again.
> Ran
>
>
Re: How to get current project's name and path [message #322755 is a reply to message #322746] Wed, 28 November 2007 08:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: noyanculum.yahoo.com

Ed How i can determine IProject?

Is there a method such:
org.eclipse.core.resources.IResource iresource = new IResource(this);


Or the code below automatically detect the current selected project?
org.eclipse.core.resources.IResource iresource;
System.out.println(iresource.getLocation());
Re: How to get current project's name and path [message #322756 is a reply to message #322755] Wed, 28 November 2007 09:00 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Well because IResource is an interface this is not very likely :-)

Tom

Noyan schrieb:
> Ed How i can determine IProject?
>
> Is there a method such:
> org.eclipse.core.resources.IResource iresource = new IResource(this);
>
>
> Or the code below automatically detect the current selected project?
> org.eclipse.core.resources.IResource iresource;
> System.out.println(iresource.getLocation());
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: How to get current project's name and path [message #322758 is a reply to message #322730] Wed, 28 November 2007 10:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: noyanculum.yahoo.com

Hello Ed and others,

I found the trick for workspace location. Here is my code:
org.eclipse.core.resources.ResourcesPlugin.getWorkspace().ge tRoot().getLocation()

When i run this for testing via "Launc an Eclipse Application" or "Run
Eclipse Application" buttons, it returns this location:
workspace: C:/Documents and Settings/rbt/My
Documents/runtime-EclipseApplication

But when i export it as a "Deployable Plug-in" (File->Export->Deployable
plug-ins and fragments), restart Eclipse and execute it as deployable
plugin. This time, it returns this location:
C:/Documents and Settings/rbt/My Documents/workspace

I wrote this for future researchers. I hope this help them.


NOW I HAVE STILL MY OTHER QUESTION
and it is more important now. Beause i want to obtain this path:
C:/Documents and Settings/rbt/My Documents/workspace/projectname

How can i get the project's name? I tried
org.eclipse.core.resources.ResourcesPlugin.getWorkspace().ge tRoot().getProject()
but this returns null..


Thank you in advance
Re: How to get current project's name and path [message #322764 is a reply to message #322755] Wed, 28 November 2007 13:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------030307080608090006060707
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Noyan,

I get the feeling you haven't read any of the basic documentation about
Eclipse's workspace APIs. I'd suggest becoming familiar with what's
available in help:

http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.user/concepts/concepts-12.htm

Folks will be far more likely to answer questions if it's clearly you've
done a little bit of homework first.


Noyan wrote:
> Ed How i can determine IProject?
>
> Is there a method such:
> org.eclipse.core.resources.IResource iresource = new IResource(this);
>
>
> Or the code below automatically detect the current selected project?
> org.eclipse.core.resources.IResource iresource;
> System.out.println(iresource.getLocation());
>
>


--------------030307080608090006060707
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Noyan,<br>
<br>
I get the feeling you haven't read any of the basic documentation about
Eclipse's workspace APIs.
Re: How to get current project's name and path [message #322765 is a reply to message #322758] Wed, 28 November 2007 13:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Noyan,

Good, you've done some homework.

Noyan wrote:
> Hello Ed and others,
>
> I found the trick for workspace location. Here is my code:
> org.eclipse.core.resources.ResourcesPlugin.getWorkspace().ge tRoot().getLocation()
>
>
> When i run this for testing via "Launc an Eclipse Application" or "Run
> Eclipse Application" buttons, it returns this location:
> workspace: C:/Documents and Settings/rbt/My
> Documents/runtime-EclipseApplication
>
> But when i export it as a "Deployable Plug-in"
> (File->Export->Deployable plug-ins and fragments), restart Eclipse and
> execute it as deployable plugin. This time, it returns this location:
> C:/Documents and Settings/rbt/My Documents/workspace
>
> I wrote this for future researchers. I hope this help them.
This will always reflect where the workspace itself is located. Project
will not necessarily be physically nested within that folder since when
a project is created you can specify anywhere in the file system at
which to locate it.
>
>
> NOW I HAVE STILL MY OTHER QUESTION
> and it is more important now. Beause i want to obtain this path:
> C:/Documents and Settings/rbt/My Documents/workspace/projectname
>
> How can i get the project's name? I tried
> org.eclipse.core.resources.ResourcesPlugin.getWorkspace().ge tRoot().getProject()
>
> but this returns null..
You really need to read some basic information. To root itself is not
in a project and projects cannot nest. If you look at the API for
IWorkspaceRoot you'll see methods like getProject(String) and
getProjects. Please try to use the Javadoc to help answer your questions...
>
>
> Thank you in advance
>
>
Re: How to get current project's name and path [message #322769 is a reply to message #322765] Wed, 28 November 2007 13:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: noyanculum.yahoo.com

>
> You really need to read some basic information. To root itself is not in a
> project and projects cannot nest. If you look at the API for
> IWorkspaceRoot you'll see methods like getProject(String) and getProjects.
> Please try to use the Javadoc to help answer your questions...
>

:)))

Dear Ed,

Do you know how i can get the selected project's name? or do you not?

However i have to thank you for all your kindly responses..

Best Regards,
Noyan
Re: How to get current project's name and path [message #322770 is a reply to message #322769] Wed, 28 November 2007 13:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Noyan,

Do you already have the selected project in hand? If not, it becomes
important to understand where you will expect this to come from...


Noyan wrote:
>>
>> You really need to read some basic information. To root itself is
>> not in a project and projects cannot nest. If you look at the API for
>> IWorkspaceRoot you'll see methods like getProject(String) and
>> getProjects. Please try to use the Javadoc to help answer your
>> questions...
>>
>
> :)))
>
> Dear Ed,
>
> Do you know how i can get the selected project's name? or do you not?
>
> However i have to thank you for all your kindly responses..
>
> Best Regards,
> Noyan
>
>
Re: How to get current project's name and path [message #322772 is a reply to message #322765] Wed, 28 November 2007 14:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: noyanculum.yahoo.com

>
> You really need to read some basic information. To root itself is not in a
> project and projects cannot nest. If you look at the API for
> IWorkspaceRoot you'll see methods like getProject(String) and getProjects.
> Please try to use the Javadoc to help answer your questions...
>

:)))))

Dear Ed,

Do you know how to get the name of the selected project? Or do you not?

However, i thank you for all your kindly responses.

Best Regards,
Noyan
Re: How to get current project's name and path [message #322775 is a reply to message #322772] Wed, 28 November 2007 14:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Noyan,

You seem to have repeated your question... Of course the answer is you
call IProject.getName, but I think you are asking about how to get "the
selected project" but you've not provided any context in which to answer
that. The IDE is full of views and can even have multiple windows, so
you'll need to narrow down the context of your question for anyone to be
able to answer it...


Noyan wrote:
>>
>> You really need to read some basic information. To root itself is
>> not in a project and projects cannot nest. If you look at the API
>> for IWorkspaceRoot you'll see methods like getProject(String) and
>> getProjects. Please try to use the Javadoc to help answer your
>> questions...
>>
>
> :)))))
>
> Dear Ed,
>
> Do you know how to get the name of the selected project? Or do you not?
>
> However, i thank you for all your kindly responses.
>
> Best Regards,
> Noyan
>
>
Re: How to get current project's name and path [message #520370 is a reply to message #322730] Fri, 12 March 2010 06:51 Go to previous messageGo to next message
shrikant  is currently offline shrikant Friend
Messages: 2
Registered: March 2010
Junior Member
Hi Noyan,
I have an novice user to eclipse PDE. Currently I am developing one plugin. In this pluging I am generating some java classes.
This is done by Wizard.
Wizard asks some question and in the end it executes the command.

So
1) Before executing the wizard i want to check whether the workspace contains any project of not? If no project then Error message.
2) If their are some projects in the workspace then which is the current active project? I mean if instead of clicking on the Project Tree if user directly invokes the Wizard from toolbar then to which project I should add those classes? I mean is their any concept like active project or main project? If yes then how to get the main project?

Can you help me in above 2 scenarios(What hooks and where they should be added)?

This is the code of execute method of command

public Object execute(ExecutionEvent event) throws ExecutionException {
MySupportWizard wizard = new MySupportWizard();
WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);
dialog.open();
return null;
}
}

Regards,
sHrik
Re: How to get current project's name and path [message #523086 is a reply to message #520370] Thu, 25 March 2010 00:43 Go to previous message
Rohit  is currently offline Rohit Friend
Messages: 24
Registered: July 2009
Junior Member
Hi Shrikant,

Did you find what you were looking for...?
I am somewhat looking for the same thing...

Thanks,
Rohit
Previous Topic:Debug JUnit test multiple times - automation? parameters?
Next Topic:Dragging around views on secondary monitor doesn't display placement hints
Goto Forum:
  


Current Time: Thu Dec 26 09:57:50 GMT 2024

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

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

Back to the top