In Eclipse, how to programmatically set JavaDoc url to write to classpath?

I have an Eclipse plugin that, among other things, can create a project and give it a few entries in the classpath. That alone works great.

These banks do not have a source, but there is a URL that can be used for Javadoc. I want to set this programmatically for these entries in the classpath that the plugin creates. This is what I do:

IClasspathEntry cpEntry; File[] jarFile = installFilePath.listFiles(); IPath jarFilePath; for (int fileCount = 0; fileCount < jarFile.length; fileCount++) { jarFilePath = new Path(jarFile[fileCount].getAbsolutePath()); cpEntry = JavaCore.newLibraryEntry(jarFilePath, null, null); entries.add(cpEntry); } 

I could not figure out how to set the location of the JavaDoc url in the claspath entry. This can be done in the Eclipse user interface - for example, if you right-click the project, go to "Properties ... →" Java Build Path "and expand one of the JAR entries and edit the" Javadoc Location ", you can specify the URL. How do it from the plugin?

+4
source share
2 answers

I am using the following:

  Path pth = new Path( MY_JARFILE_LOCATION ); Path pthd = new Path( MY_JAVADOC_LOCATION ); ClasspathAttribute att = new ClasspathAttribute("javadoc_location", "file:" + pthd.toOSString()); IClasspathAttribute[] atts = new IClasspathAttribute[] { att }; IClasspathEntry cpISDI = JavaCore.newLibraryEntry(pth, null, null, null, atts, false); cpEntries.add(1, cpISDI); 

(edited formatting)

+1
source

Yakir's answer is correct, but it is better to use the public factory method JavaCore.newClasspathAttribute() rather than directly constructing ClasspathAttribute (which is a private Eclipse API). For instance:

 File javadocDir = new File("/your/path/to/javadoc"); IClasspathAttribute atts[] = new IClasspathAttribute[] { JavaCore.newClasspathAttribute("javadoc_location", javadocDir.toURI().toString()), }; IClasspathEntry cpEntry = JavaCore.newLibraryEntry(libraryPath, null, null, null, atts, false); 
+1
source

All Articles