在Eclipse中,如何以编程方式在类路径条目上设置JavaDoc URL?

我有一个
Eclipse插件,除其他外,它可以创建一个项目并给它几个类路径条目.这本身就可以.

这些jar没有包含的源,但是有一个可以用于Javadoc的URL.我想以编程方式为插件创建的这些类路径条目设置它.这就是我正在做的事情:

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

我无法弄清楚如何在claspath条目上设置JavaDoc URL位置.这可以在Eclipse UI中完成 – 例如,如果右键单击项目,请转到属性… – > Java Build Path,并展开其中一个JAR条目并编辑“Javadoc Location”,您可以指定一个URL.如何在插件中执行此操作?

最佳答案 yakir的答案是正确的,但最好使用公共工厂方法JavaCore.newClasspathAttribute()而不是直接构造ClasspathAttribute(这是Eclipse私有API).例如:

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