Domanda

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

È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top