简体   繁体   中英

How do I generate test javadoc for projects that contain package-info files with maven?

I'm trying to build the site for a Java project I'm working on. The project contains several package-info.java files. The project itself is a Java 8 targeted project being built with Eclipse Adoptium JDK 11.0.15.10-hotspot. To build the javadoc, I'm using the maven javadoc plugin. Maven builds the main javadoc fine. However, when it builds the test javadoc, it complains about the package-info.class file containing the wrong class. For example:

javadoc: error - An internal exception has occurred.
        (com.sun.tools.javac.code.ClassFinder$BadClassFile: bad class file: C:\workspaces\releases\9.99.0\foo-bar-baz\target\classes\com\mycompany\foo\bar\baz\package-info.class
  class file contains wrong class: com\mycompany\foo\bar\baz\package-info
  Please remove or make sure it appears in the correct subdirectory of the classpath.)

Naturally I assumed that I had some misspelling of the package name. But that doesn't seem to be the case. The java file reads like this:

/**
 * <p>
 * Some really cool javadoc about this package.
 * </p>
 */
package com.mycompany.foo.bar.baz;

This looks right. So I'm a bit puzzled. What is causing the javadoc executable to complain that the package-info contains the wrong class?

I was curious, so I looked at the class file using javap -v and got the following:

javap -v package-info.class
Classfile /C:/workspaces/releases/9.99.0/foo-bar-baz/target/classes/com/mycompany/foo/bar/baz/package-info.class
  Last modified Jun 5, 2022; size 142 bytes
  MD5 checksum xxxxxxxxxxxxxxxxxxxxxxxxxxx
  Compiled from "package-info.java"
interface com\mycompany\foo\bar\baz\package-info
  minor version: 0
  major version: 52
  flags: (0x1600) ACC_INTERFACE, ACC_ABSTRACT, ACC_SYNTHETIC
  this_class: #3                          // "com\\mycompany\\foo\\bar\\baz\\package-info"
  super_class: #5                         // java/lang/Object
  interfaces: 0, fields: 0, methods: 0, attributes: 1
Constant pool:
  #1 = Utf8               package-info.java
  #2 = Utf8               com\\mycompany\\foo\\bar\\baz\\package-info
  #3 = Class              #2              // "com\\mycompany\\foo\\bar\\baz\\package-info"
  #4 = Utf8               java/lang/Object
  #5 = Class              #4              // java/lang/Object
  #6 = Utf8               SourceFile
{
}
SourceFile: "package-info.java"

It turns out the process of generating these package-info classes used incorrect slashes. After doing some digging, it looks like this was the result of a defect in maven-compiler-plugin 3.10.0 ( https://issues.apache.org/jira/browse/MCOMPILER-485 ). Updating to 3.10.1 fixed this issue. Alternatively, compiling in Linux using version 3.10.0 works as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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