简体   繁体   English

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

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

I have an Eclipse plugin, that among other things, can create a project and give it several classpath entries. 我有一个Eclipse插件,除其他外,它可以创建一个项目并为其提供几个类路径条目。 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. 这些罐子没有包含源,但是有一个可用于Javadoc的URL。 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. 我不知道如何在claspath条目上设置JavaDoc URL位置。 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. 这可以在Eclipse UI中完成-例如,如果右键单击项目,转到“属性...-> Java构建路径”,然后展开其中一个JAR条目并编辑“ Javadoc位置”,则可以指定网址。 How do I do this from within a plug-in? 如何从插件中执行此操作?

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) (格式编辑)

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). yakir的答案是正确的,但是最好使用公共工厂方法JavaCore.newClasspathAttribute()而不是直接构造ClasspathAttribute (这是Eclipse专用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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM