Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » JavaCore - new classpath Entries(no possibility for relative paths?)
JavaCore - new classpath Entries [message #1791277] Wed, 27 June 2018 13:23 Go to next message
Antonio Bloise is currently offline Antonio BloiseFriend
Messages: 3
Registered: February 2017
Junior Member
Hi eclipse community,

currently i am working on own projects for which i want to set the classpathentries by code.

this works currently fine, i can add relative paths.

now i tried to add an embedded jar file by code, which failed with every method from JavaCore which creates a new IClasspathEntry (newScriptEntry, newLibraryEntry, newProjectEntry....): all i get is:

org.eclipse.jdt.internal.core.ClasspathEntry$AssertionFailedException: Path for IClasspathEntry must be absolute

But when i use the "Add Jar" Button within Java Build Path -> Libraries and i select the embedded jarfile, following entry will be generated:

<classpathentry kind="lib" path="libs/report.jar"/>


how can i add those by code without getting an assertion? Seems strange to me.... but i could not debug/find the source point where "Add jar" does it's magic.

thanks for help.
Re: JavaCore - new classpath Entries [message #1791372 is a reply to message #1791277] Thu, 28 June 2018 12:25 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1627
Registered: July 2009
Senior Member
The "magic" happens in org.eclipse.jdt.internal.core.ClasspathEntry.elementDecode(Element, IJavaProject, Map), see the comment
// ensure path is absolute

where the project name is prepended if necessary.

In your code you should do the same before calling newLibraryEntry(): change "lib/some.jar" to "/MyProject/lib/some.jar". The latter is an "absolute" workspace path, so don't worry about portability, "absolute" here does not imply any explicit path in your local filesystem ...

HTH,
Stephan
Re: JavaCore - new classpath Entries [message #1791390 is a reply to message #1791372] Thu, 28 June 2018 14:53 Go to previous messageGo to next message
Antonio Bloise is currently offline Antonio BloiseFriend
Messages: 3
Registered: February 2017
Junior Member
Hi Stephan,

thank you very much for this information. It does not matter if i add the full path or the shortened form, the classpathentries will be generated / updated individually, so that this isn't an issue. i'll take the shortform, it indicates just that this library is inside a project folder.


yet another idea/question?
I am not sure if i really should open a new thread, but somehow i am curious about this constelation:

what if i am using my own protocol handler? in my tests i added the URL of this protocal with JavaCore -> which is working, the entries are there. but somehow they are not available in classpath (respective: i don't see any code completion in this case):
currently i am just extracting the bin folder out of the (custom defined) archive.... but maYbe that's the solution.
greetings,
Antonio
Re: JavaCore - new classpath Entries [message #1791395 is a reply to message #1791390] Thu, 28 June 2018 17:43 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1627
Registered: July 2009
Senior Member
Quote:
what if i am using my own protocol handler?


I don't see an easy way to integrate this. A ClasspathEntry is based on an IPath not a URL (only an index location can be referenced using an URL, but not the jar etc. itself).
Similar observations hold for other representations down the line like, e.g,. JarPackageFragmentRoot. IOW, the assumption that all dependencies can be accessed in the local file system seems to be deeply engraved in JDT.

Also see that integrations like m2e, PDE ... feed dependencies into the build by downloading first, not by referencing some location in the net.
Previous Topic:Focus losing when .xml file opened with CTRL-SHIFT-R
Next Topic:Usage of org.eclipse.ltk.core.refactoring.Refactoring
Goto Forum:
  


Current Time: Tue Sep 25 09:24:25 GMT 2018

Powered by FUDForum. Page generated in 0.02264 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top