In Eclipse, how to set JavaDoc URL on a classpath entry programmatically?

╄→гoц情女王★ 提交于 2019-12-10 15:49:19

问题


I have an Eclipse plugin, that among other things, can create a project and give it several classpath entries. This in and of itself works fine.

These jars do not have source included in the, however there is a URL that can be used for Javadoc. I want to set this up programmatically for these classpath entries that the plug-in creates. This is what I'm doing:

  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 JavaDoc URL location on a claspath entry. This can be done in the Eclipse UI - for instance, 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 a URL. How do I do this from within a plug-in?


回答1:


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

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);



回答2:


I use 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)



来源:https://stackoverflow.com/questions/2015244/in-eclipse-how-to-set-javadoc-url-on-a-classpath-entry-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!