【问题标题】:How to Get a Project Path in Java..?如何在 Java 中获取项目路径..?
【发布时间】:2016-08-24 01:56:01
【问题描述】:

我正在为 Eclipse 开发一个 java 插件,我需要从插件中获取项目路径 示例

/home/user/workspace/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 $?");
            }
        }

【问题讨论】:

标签: java eclipse plugins path project


【解决方案1】:

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

你想要的是getLocation(),它返回文件系统中项目(或其他资源)的完整路径:

IPath path = project.getLocation();

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

String pathStr = path.toOSString();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多