maven-javadoc-plugin错误javadoc:错误-无法读取目录名称中包含非ASCII字符的输入长度= 1 [英] maven-javadoc-plugin error javadoc: error - cannot read Input length = 1 with non-ASCII characters in directory name
问题描述
我正在Windows 10上使用OpenJDK11.我有一个非常简单的POM,用于生成Javadocs的单个Java文件.这是摘录:
I'm using OpenJDK 11 on Windows 10. I have a very simple POM, for a single Java file, that generates Javadocs. Here is an extract:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
奇怪的是,刚运行mvn clean package
会导致错误:
Strangely just running mvn clean package
causes an error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.0.1:jar (default) on project foobar: MavenReportException: Error while generating Javadoc:
[ERROR] Exit code: 1 - javadoc: error - cannot read Input length = 1
[ERROR]
[ERROR] Command line was: C:\bin\jdk-11\bin\javadoc.exe @options @packages
在target/apidocs
中只有三个文件:javadoc.bat
,options
和packages
. options
文件是最有趣的.它会在所有地方明确地显示UTF-8
.但请看以下几行:
In target/apidocs
there are only three files: javadoc.bat
, options
, and packages
. The options
file is the most interesting. It explicitly says UTF-8
everywhere, as it should. But look at these lines:
-sourcepath
C:/projects/li��o 1/src/main/java
该项目在C:\projects\lição 1
中.看来,沿着Java或Maven链或Javadoc插件链的某个地方,未正确将目录名转换为UTF-8.
This project is in C:\projects\lição 1
. It appears that somewhere along the chain Java or Maven or the Javadoc plugin didn't correctly convert the directory name to UTF-8.
果然;当我在Windows中重命名目录以删除非ASCII字符时,mvn clean package
正常工作.
Sure enough; when I renamed the directories in Windows to remove non-ASCII characters, mvn clean package
worked just fine.
这似乎是一个明显的错误;一旦Maven启动,所有内容都应该是UTF-8. Javadoc插件有问题吗?任何人都知道这起源于何处?我应该在哪里提交故障单?还是我做错了什么?
This would seem like a blatant bug; once Maven starts, everything should be UTF-8 throughout. Is it a problem with the Javadoc plugin? Anyone have an idea where this originates? Where should I file a bug ticket? Or am I doing something wrong?
推荐答案
正如您所说,这看起来像是用于将文件写入target/apidocs
的编码.
As you say, this looks like the encoding used to write the files to target/apidocs
.
仔细查看maven-javadoc-plugin的源代码,它只是在编写这些文件时使用平台编码-例如
Looking through the source for the maven-javadoc-plugin, it is just using the platform encoding when writing these files - e.g. this line.
在调用Maven时直接设置编码对我来说修复了上面的示例:
Directly setting the encoding while calling Maven repaired the example above for me:
mvn clean package -Dfile.encoding=UTF-8
尽管感觉更像是一种解决方法,而不是一个好的解决方案-它需要假设没有其他依赖于Maven构建中的平台编码的东西.
This feels more like a workaround than a good fix though - it needs to assume there is nothing else depending on the platform encoding in the Maven build.
我认为原因是主JDK在8到9之间发生了变化.解析参数文件(例如javadoc命令行中的@options
)的代码段(实际上在javac下)已从使用平台切换到编码在此调用Files.newBufferedReader()
Files.newBufferedReader(Path)指出,如果未指定编码,则使用UTF-8.这意味着在javac和javadoc中的参数文件现在都必须以UTF-8编码.
I think the cause is a change in the main JDK between 8 and 9. The bit of code (actually under javac) that parses the argument files (e.g. @options
in the javadoc command line) has switched from using the platform encoding here to calling Files.newBufferedReader()
here. Files.newBufferedReader(Path) states that it uses UTF-8 if the encoding is not specified. This means argument files, in both javac and javadoc, must now be encoded in UTF-8.
这篇关于maven-javadoc-plugin错误javadoc:错误-无法读取目录名称中包含非ASCII字符的输入长度= 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!