I’m currently developing an Eclipse plugin and I’m a bit lost…
I have a custom nature and I want to add a .jar to the classpath of the user projects when the user adds this nature (I want to update the classpath of the project in the configure() method of my nature).
I just can’t find out how to do that… I think I understood that I have to “map” this .jar to an IClasspathEntry that I could then add to my IJavaProject. The questions are how to cleanly include this jar in my plugin and how to “map” it to an IClasspathEntry (the .jar is currently in a lib folder at the root of my plugin project)
Thank you in advance for your time !
Valentin
First, how to map it to a classpath entry:
IClasspathEntry jar = JavaCore.newLibraryEntry(new Path(jarPath), null, null)Then you can add this IClasspathEntry to the end of the project’s existing classpath and set it, using the get/setRawClasspath methods found in IJavaProject:
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/IJavaProject.html
Keeping this jar in your lib directory is fine, but you might need to make sure that your plugin gets unzipped when it’s installed (rather than staying as a .jar in the /plugins directory) or this jar won’t be accessible to the project. You can find the path to this jar using the FileLocator class:
http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fcore%2Fruntime%2FFileLocator.html