这是 Maven Javadoc 插件使用的一个典型项目:
yourproject |-- src |-- main | |-- java | | |-- org | | |-- apache | | |-- myapp | | `-- App.java | |-- javadoc | `-- overview.html | |-- org | |-- apache | |-- myapp | `-- package.html | |-- doc-files | `-- app.png |-- test |-- java | |-- org | |-- apache | |-- myapp | `-- AppTest.java |-- javadoc `-- overview.html |-- org |-- apache |-- myapp `-- package.html |-- doc-files `-- app.png
您需要在 pom.xml 中配置 Maven Javadoc 插件,例如:
<project> ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>3.3.2</version> <configuration> <doctitle>My API for ${project.name} ${project.version}</doctitle> <!-- Used by javadoc:javadoc goal --> <windowtitle>My API for ${project.name} ${project.version}</windowtitle> <!-- Used by javadoc:javadoc goal --> <testDoctitle>My Test API for ${project.name} ${project.version}</testDoctitle> <!-- Used by javadoc:test-javadoc goal --> <testWindowtitle>My Test API for ${project.name} ${project.version}</testWindowtitle> <!-- Used by javadoc:test-javadoc goal --> ... </configuration> </plugin> </plugins> </build> ... </project>
您可以调用mvn javadoc:test-javadoc或mvn site。有关详细信息,请参阅javadoc:test-javadoc 参数。
备注:
您可能还需要对 Javadoc 报告和测试 Javadoc 报告进行不同类型的配置。为此,您需要在 pom.xml 中配置 Maven Javadoc 插件来处理 <reportSets/> 配置参数,例如:
<project> ... <reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>3.3.2</version> <reportSets> <reportSet> <id>html</id> <configuration> <doctitle>My API for ${project.name} ${project.version}</doctitle> <windowtitle>My API for ${project.name} ${project.version}</windowtitle> ... </configuration> <reports> <report>javadoc</report> </reports> </reportSet> <reportSet> <id>test-html</id> <configuration> <testDoctitle>My Test API for ${project.name} ${project.version}</testDoctitle> <testWindowtitle>My Test API for ${project.name} ${project.version}</testWindowtitle> ... </configuration> <reports> <report>test-javadoc</report> </reports> </reportSet> </reportSets> </plugin> </plugins> </reporting> ... </project>
您需要调用mvn site。