【问题标题】:In Eclipse, how to set JavaDoc URL on a classpath entry programmatically?在 Eclipse 中,如何以编程方式在类路径条目上设置 JavaDoc URL?
【发布时间】:2011-01-02 04:22:32
【问题描述】:

我有一个 Eclipse 插件,除其他外,它可以创建一个项目并为其提供几个类路径条目。这本身就可以正常工作。

这些 jars 中没有包含源代码,但是有一个可用于 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 中完成 - 例如,如果您右键单击项目,转到 Properties... -> Java Build Path,然后展开其中一个 JAR 条目并编辑“Javadoc Location”,您可以指定一个网址。如何在插件中执行此操作?

【问题讨论】:

    标签: eclipse plugins javadoc eclipse-jdt


    【解决方案1】:

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

    【讨论】:

    • 您也可以将JavaCore.newClasspathAttribute("javadoc_location", ...替换为JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, ...
    【解决方案2】:

    我使用以下内容:

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

    (编辑格式)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-03
      • 1970-01-01
      • 2014-04-06
      • 2011-04-17
      • 1970-01-01
      • 2020-08-01
      • 2010-10-01
      • 1970-01-01
      相关资源
      最近更新 更多