Get relative path from absolute URI for EObject
-
22-12-2019 - |
Pergunta
I have an URI for an EObject, which looks like this:
file:/C:/runtime-run123.product/Project1/examples/Apple.ecore#/
I get the URI by calling EcoreUtil.getURI(ePackage)
, where ePackage is an instance of the class EPackage
.
How can I get the relative path from that URI? The result should be: /Project1/examples/Apple.ecore
Solução
You can use IFile#getFullPath
to get relative path. You need to convert from EObject
to IFile
first.
Example:
URI uri = EcoreUtil.getURI(eObject);
IPath path = new Path(uri.toFileString());
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
System.out.println(file.getFullPath()); // Relative path
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow