2016-04-29 29 views
0

我在一个Java的Eclipse插件工作,我需要从插件 例如何在Java中获取项目路径..?

/家庭/用户/工作区/ PROJECT_NAME/

拿到项目条路,我不知道怎么办。

我试过,但没有奏效

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 $?"); 
      } 
     } 
+1

尝试看看这个帖子[这里已经reposonded(http://stackoverflow.com/questions/13011892/how-to-locate-the-path-of-the-current-项目中的Java月食) – murthy

回答

1

getFullPath()返回相对于工作空间根项目的路径。

你想要的是getLocation()这在文件系统会返回该项目的完整路径(或其他资源):

IPath path = project.getLocation(); 

使用IPathtoOSString()方法将路径转换为字符串以正确的格式当前OS:

String pathStr = path.toOSString();