Eclipse PDE: given a relative path like /ProjectName/lib/something.jar, how do you get the full path to the file system?

I am trying to find the path to the jar file which is in the rawpathpath. getRawClasspath returns a collection of IClasspathEntry objects. I can call getPath on them.

But getPath returns something strange: IPath starting with the project name, for example:

/ProjectName/lib/something.jar

What is the right way to turn this relative path into a full-fledged path to the OS? At first it seemed to me that I could just add the path to the root of the workspace, but this does not work, since intermediate directories often exist between the workspace and the project.

And overall, how do I know what to do with the IPath returned by the method? It seems like I never know what IPath is; regarding the project, regarding the workspace, regarding the project, but with the name of the project as the first element regarding the moon phase ... All this is puzzling, and the documentation is never useful - or at least I don’t know where to look.

UPDATE

Now I'm even more confused. The problem still is that when you have IClasspathEntry, it is still not clear to me how to resolve its path to the file system.

, : " /it ( ), . , getPath IClasspath : , , , IPath, /, . , . , , " " , .

, , IPath . , , . , .

, ?

+5
4

:

    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IResource res = root.findMember("/ProjectName/lib/something.jar");
    System.out.println(res.getLocation().toString());
+5

Eclipse , , , , ( JRE), .

, getResolvedClasspath, "" ( , ). Javadoc, , :

  • CPE_LIBRARY - , ( , findMember). ,
  • CPE_PROJECT -
  • CPE_SOURCE -

. , getLocation.

1 1 . - , ( ) .

+1

, , , :

private IPath getCorrectAbsolutePath(IJavaProject project, IPath path) throws IllegalArgumentException {
    final String projectName = project.getProject().getName();
    if (path.segmentCount() > 1 && path.segment(0).equals(projectName)) {
        IPath projectAbsolutePath = project.getProject().getLocation();
        IPath relativePath = path.removeFirstSegments(1);
        return projectAbsolutePath.append(relativePath);
    } else {
        if (!path.isAbsolute())
            path = path.makeAbsolute();
        if (!path.isAbsolute())
            throw new IllegalArgument("Cannot make IPath absolute: " + path.toString()); 
        return path;
    }
}
0

I have a suggestion, look at the image attachment, find the "location" property from the properties of any eclipse plugin, maybe it will find it, where it comes from. but sorry, I do not have 10 reputation, you can see the picture from the picture URL

-2
source

All Articles