javadoc 子集/java 库组织

发布于 2024-11-02 23:42:34 字数 396 浏览 7 评论 0原文

我自己从来没有运行过javadoc(无论是在命令行还是ant的javadoc任务 ;我将使用 ant)——我需要为我编写的库生成 javadoc。

问题是我的java库被组织成几个包,并且Java中没有办法使类在库内公开但不向外界公开,所以我有一堆public 从实现的角度来看,而不是从库的角度来看语义的角度。

所以我需要弄清楚两件事。

  1. (短期解决方案)有没有办法为我的库的使用者使用的类/接口/方法的特定子集生成 javadoc?

  2. 我如何重组图书馆以确保公共意味着公共?

I've never run javadoc myself (whether at command-line or ant's javadoc task; I'll be using ant) -- I need to produce a javadoc for a library that I've written.

The problem is that my java library is organized into several packages, and there's no way in Java to make classes public within a library but not public to the outside world, so I have a bunch of classes that are public from an implementation standpoint but not a semantic standpoint from the library's point of view.

So I need to figure out two things.

  1. (short-term solution) Is there a way of producing javadoc for a specific subset of classes/interfaces/methods that are meant to be used by consumers of my library?

  2. How could I reorganize the library to make sure that public means public?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

各自安好 2024-11-09 23:42:34

如果您可以通过包将公共公共内部公共类分开(即有一些包包含您的库用户所需的所有公共类,并且没有其他公共类)类),然后仅在这些包上运行 Javadoc。

Javadoc 的工作原理是提供要使用的包的列表(以及用于查找这些包的源路径),并仅生成这些包的文档。

对于 Ant,情况会稍微复杂一些,因为使用 javadoc 任务的最简单方法是使用 ,默认情况下会采用给定目录中的所有包。

这是一个只有一个包的示例:

  <target name="javadoc">
    <javadoc destdir="${javadoc}"
         encoding="US-ASCII"
         charset="UTF-8"
         docencoding="UTF-8"
         use="yes"
         windowtitle="JSch API"
             sourcepath="${src}"
         >
      <arg value="-notimestamp" />
      <package name="com.jcraft.jsch" />
      <doctitle>JSch – Java Secure Channel ${version}</doctitle>
      <bottom>This is an inofficial Javadoc created by Paŭlo Ebermann.
    Have a look at the <a href="http://www.jcraft.com/jsch/">official homepage</a>.
      </bottom>
      <link href="http://download.oracle.com/javase/6/docs/api/" />
    </javadoc>
  </target>

您可以查看结果,但它是事实上这不是一个很好的例子,因为这里的主包包含许多供消费者使用的类。


如果您处于像 JSch 这样的情况,即您无法通过包将 public public内部 public 类分开,因为您有包含公共类型和私有类型的包,还有办法做到这一点。 Javadoc 还支持不提供包名称,而是提供单个文件名作为参数。由于我刚刚花了一些时间弄清楚如何使用 ant 执行此操作,因此生成的 ant 目标代码如下:

  <target name="simple.javadoc">
    <javadoc destdir="${simple.javadoc}"
             encoding="US-ASCII"
             charset="UTF-8"
             docencoding="UTF-8"
             use="yes"
             windowtitle="simple JSch API"
             excludepackagenames="*"
             sourcepath="${src}"
             >
      <arg value="-notimestamp" />
      <sourcefiles>
        <resourcelist encoding="US-ASCII">
          <file file="simpleclasses.list" />
        </resourcelist>
      </sourcefiles>
      <doctitle>JSch – Java Secure Channel ${version} (simplified version)</doctitle>
      <bottom>This is a simplified version of the <a href="http://epaul.github.com/jsch-documentation/javadoc/">inofficial Javadoc</a> created by Paŭlo Ebermann.
        Have a look at the <a href="http://www.jcraft.com/jsch/">official homepage</a>.
      </bottom>
      <link href="http://download.oracle.com/javase/6/docs/api/" />
    </javadoc>
  </target>

源文件列于 simpleclasses.list 此处,使用 resourcelist。我认为带有 includesfile=... 的简单文件集也可以工作(并且它也将允许模式而不是简单的列表)。

我必须搜索很长一段时间的重要一点:如果您提供 sourcepath 属性,但不提供任何 packagenames 属性或 子元素,除了提到的文件之外,ant 将自动提供“所有包”默认值,这会导致不排除任何内容。 (我们希望此处的 sourcepath 允许从未记录的类继承文档。)因此,我们还必须提供 excludepackagenames="*",这样现在只有 < code>元素定义要记录的内容。

结果现在看起来好多了,感谢您的提问。

If you can separate the public public from the internal public classes by package (i.e. have some packages which contain all the public classes needed for users of your library, and no other public classes), then simply run Javadoc only on these packages.

Javadoc works by giving a list of packages to be used (and additionally a source path to look for those packages), and produces documentation only for these packages.

With Ant it is a bit more complicated, since the easiest way to use the javadoc task, using a <packageset>, takes by default all packages in the given directory.

Here is an example with only one package:

  <target name="javadoc">
    <javadoc destdir="${javadoc}"
         encoding="US-ASCII"
         charset="UTF-8"
         docencoding="UTF-8"
         use="yes"
         windowtitle="JSch API"
             sourcepath="${src}"
         >
      <arg value="-notimestamp" />
      <package name="com.jcraft.jsch" />
      <doctitle>JSch – Java Secure Channel ${version}</doctitle>
      <bottom>This is an inofficial Javadoc created by Paŭlo Ebermann.
    Have a look at the <a href="http://www.jcraft.com/jsch/">official homepage</a>.
      </bottom>
      <link href="http://download.oracle.com/javase/6/docs/api/" />
    </javadoc>
  </target>

You can view the result, but it is in fact not a really good example, as the main package here contains lots of classes which are not for use by consumers.


If you are in a situation like JSch, i.e. you can't separate the public public from the internal public classes by package since you have packages containing both public and private types, there is still a way to do this. Javadoc also supports giving not package-names, but individual file names as parameters. As I just spent some time to figure out how to do this with ant, here the resulting ant target code:

  <target name="simple.javadoc">
    <javadoc destdir="${simple.javadoc}"
             encoding="US-ASCII"
             charset="UTF-8"
             docencoding="UTF-8"
             use="yes"
             windowtitle="simple JSch API"
             excludepackagenames="*"
             sourcepath="${src}"
             >
      <arg value="-notimestamp" />
      <sourcefiles>
        <resourcelist encoding="US-ASCII">
          <file file="simpleclasses.list" />
        </resourcelist>
      </sourcefiles>
      <doctitle>JSch – Java Secure Channel ${version} (simplified version)</doctitle>
      <bottom>This is a simplified version of the <a href="http://epaul.github.com/jsch-documentation/javadoc/">inofficial Javadoc</a> created by Paŭlo Ebermann.
        Have a look at the <a href="http://www.jcraft.com/jsch/">official homepage</a>.
      </bottom>
      <link href="http://download.oracle.com/javase/6/docs/api/" />
    </javadoc>
  </target>

The source files are listed in simpleclasses.list here, using a resourcelist. I think a simple fileset with includesfile=... would have worked, too (and it also would have allowed patterns instead of a simple list).

The important point I had to search quite a while: If you give a sourcepath attribute and do not give any packagenames attribute or <package> subelement, ant will automatically provide an "all packages" default, in addition to the mentioned files, which results on not excluding anything. (We want the sourcepath here to allow inheriting documentation from non-documented classes.) So, we have to also provide excludepackagenames="*", such that now only the <sourcefiles> element defines what would be documented.

The result looks now much nicer, thanks for the question.

◇流星雨 2024-11-09 23:42:34

首先,有一种简单的方法可以使用 OSGi 使外部接口可用,同时隐藏内部接口。至少这是第二个问题的答案。

如果您想在一个子集上运行 javadoc,您也可以随时将项目分解为多个源代码树...

First, there is an easy way to make external interfaces available while hiding internals, using OSGi. This is the answer to #2, at least.

You could always break the project down into multiple source trees, too, if you wanted to run javadoc over a subset...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文