Eclipse plugin 获取Eclipse中IFile的模块相对路径
我创建了一个Eclipse plugin 获取Eclipse中IFile的模块相对路径,eclipse-plugin,eclipse-rcp,Eclipse Plugin,Eclipse Rcp,我创建了一个IFile实例,如下所示: IPath filePath = new Path(WebContent/folder1/file1.html); IFile file = project.getFile(filePath); 该文件将部署在服务器上,我需要获取模块的相对路径(在本例中为/folder1/file1.html) 我曾经尝试过这样使用IFlatFile类: IFlatFile flatFile = new FlatFile(file, file.getName(), fi
IFile
实例,如下所示:
IPath filePath = new Path(WebContent/folder1/file1.html);
IFile file = project.getFile(filePath);
该文件将部署在服务器上,我需要获取模块的相对路径(在本例中为/folder1/file1.html
)
我曾经尝试过这样使用IFlatFile
类:
IFlatFile flatFile = new FlatFile(file, file.getName(), file.getProjectRelativePath());
IPath modulePath = flatFile.getModuleRelativePath();
但是getModuleRelativePath()
似乎返回了创建实例时我提供给构造函数的相同路径
有没有其他方法可以获取给定文件的模块相对路径?查看
平面文件的源代码getModuleRelativePath
只返回传递给构造函数的路径。我想我可以执行类似path=path.removeFirstSegments(1)的操作
但这肯定不是最好的方法,因为在某些情况下,这可能会导致问题circumstances@CIOC:您可以试试:file.getFullPath().makeRelative()
看看它是否返回您想要的内容吗?我试过file.getFullPath().makeRelative()
但它返回项目相对路径,例如:/WebContent/file.html