0

I am working in a java plugin for Eclipse and i need get the project path from plugin Example

/home/user/workspace/project_name/

And i dont know how.

I tried this but it did not work

if (window != null)
        {
            IStructuredSelection selection = (IStructuredSelection) window.getSelectionService().getSelection();
            Object firstElement = selection.getFirstElement();
            if (firstElement instanceof IAdaptable)
            {
                IProject project = (IProject)((IAdaptable)firstElement).getAdapter(IProject.class);
                IPath path = project.getFullPath();
               // System.out.println(path);
                Runtime.getRuntime().exec("zenity --warning --text '"+path+"';echo $?");
            }
        }
Chirag Sondagar
  • 427
  • 1
  • 4
  • 15
  • 1
    Try look into this post [already reposonded here](http://stackoverflow.com/questions/13011892/how-to-locate-the-path-of-the-current-project-in-java-eclipse) – murthy Apr 29 '16 at 04:22

1 Answers1

1

getFullPath() returns the path of the project relative to the workspace root.

What you want is getLocation() which returns the full path of the project (or other resource) in the file system:

IPath path = project.getLocation();

Use the IPath toOSString() method to convert the path to a string in the correct format for the current OS:

String pathStr = path.toOSString();
greg-449
  • 109,219
  • 232
  • 102
  • 145