使用 Eclipse 编译器而不是 javac 会导致 javadoc 崩溃
摘要:
我遇到了一个有趣的问题,我不太确定如何解决它:
- 我们的项目几个月来一直运行良好,
- 我将
maven-compiler-plugin
更改为使用 < code>eclipse 编译器而不是javac
- 现在,当我运行
mvn site
时,maven-javadoc-plugin
失败 - 根据堆栈跟踪,看起来 Javadoc 工具是Eclipse 编译器创建的类文件崩溃
有什么办法可以解决这个问题吗?如果没有,至少有什么方法可以进一步调试它吗?
完整详细信息:
我正在使用 Java 1.6.0_27 和 Maven 3.0.2。
我一直在使用 javac 编译器来构建我们的代码库,但我有兴趣尝试 Eclipse 编译器,因为它会产生更好的警告(并且在其他方面更容易配置)。
因此,我将 pom.xml 中的 maven-compiler-plugin
的定义更改为:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerId>eclipse</compilerId>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-warn:+boxing,enumSwitch,javadoc,hashCode</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>1.8.2</version>
</dependency>
</dependencies>
</plugin>
在我的
部分中,我有:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
</plugin>
到目前为止,一切都很好。我进行了mvn clean install
,一切都构建得很好,所有测试都通过了,一切看起来都很棒。
但是,当我尝试运行 mvn site
时,当它到达 Javadoc 报告时,它失败并出现 Javadoc 崩溃:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.0:site (default-site) on project framework: Error during page generation: Error rendering Maven report:
[ERROR] Exit code: 1 - java.lang.StringIndexOutOfBoundsException: String index out of range: -15
[ERROR] at java.lang.String.substring(String.java:1937)
[ERROR] at java.lang.String.substring(String.java:1904)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.simpleBinaryName(ClassReader.java:958)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readEnclosingMethodAttr(ClassReader.java:930)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readMemberAttr(ClassReader.java:909)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readClassAttr(ClassReader.java:1053)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readClassAttrs(ClassReader.java:1067)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readClass(ClassReader.java:1560)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readClassFile(ClassReader.java:1658)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:1845)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:1777)
[ERROR] at com.sun.tools.javac.code.Symbol.complete(Symbol.java:386)
[ERROR] at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:763)
[ERROR] at com.sun.tools.javac.code.Symbol$ClassSymbol.flags(Symbol.java:695)
[ERROR] at com.sun.tools.javadoc.ClassDocImpl.getFlags(ClassDocImpl.java:105)
[ERROR] at com.sun.tools.javadoc.ClassDocImpl.isAnnotationType(ClassDocImpl.java:116)
[ERROR] at com.sun.tools.javadoc.DocEnv.isAnnotationType(DocEnv.java:574)
[ERROR] at com.sun.tools.javadoc.DocEnv.getClassDoc(DocEnv.java:546)
[ERROR] at com.sun.tools.javadoc.PackageDocImpl.getClasses(PackageDocImpl.java:154)
[ERROR] at com.sun.tools.javadoc.PackageDocImpl.addAllClassesTo(PackageDocImpl.java:170)
[ERROR] at com.sun.tools.javadoc.RootDocImpl.classes(RootDocImpl.java:178)
[ERROR] at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.startGeneration(AbstractDoclet.java:96)
[ERROR] at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.start(AbstractDoclet.java:64)
[ERROR] at com.sun.tools.doclets.formats.html.HtmlDoclet.start(HtmlDoclet.java:42)
[ERROR] at com.sun.tools.doclets.standard.Standard.start(Standard.java:23)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:597)
[ERROR] at com.sun.tools.javadoc.DocletInvoker.invoke(DocletInvoker.java:269)
[ERROR] at com.sun.tools.javadoc.DocletInvoker.start(DocletInvoker.java:143)
[ERROR] at com.sun.tools.javadoc.Start.parseAndExecute(Start.java:340)
[ERROR] at com.sun.tools.javadoc.Start.begin(Start.java:128)
[ERROR] at com.sun.tools.javadoc.Main.execute(Main.java:41)
[ERROR] at com.sun.tools.javadoc.Main.main(Main.java:31)
[ERROR]
[ERROR] Command line was: "C:\Program Files (x86)\Java\jdk1.6.0_27\jre\..\bin\javadoc.exe" @options @packages
[ERROR]
[ERROR] Refer to the generated Javadoc files in 'C:\Projects\SMF\framework\target\site\apidocs' dir.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
我的问题:
好的,那么发生了什么变化?当我使用 javac 时,所有 Javadoc 和 Maven 站点都构建得很好,但是当我切换到 Eclipse 编译器时,Javadoc 就崩溃了。
更糟糕的是,它甚至没有告诉我哪个类导致它崩溃,所以我什至不知道从哪里开始调试它。
显然,目前这意味着我不会使用 Eclipse 编译器,而是会继续使用 javac。但我很好奇为什么会发生这种情况,以及我可以采取哪些措施来修复或解决它。
Summary:
I've run into an interesting problem, and I'm not quite sure how to sleuth it:
- Our project has been building fine for months
- I changed the
maven-compiler-plugin
to use theeclipse
compiler instead ofjavac
- Now when I run
mvn site
,maven-javadoc-plugin
fails - According to the stack trace, it appears the Javadoc tool is crashing on a class file created by the Eclipse compiler
Is there any way to fix this? If not, is there at least any way to debug it further?
Full details:
I'm using Java 1.6.0_27 and Maven 3.0.2.
I've been using the javac compiler to build our codebase, but I'm interested in trying the Eclipse compiler, since it produces much better warnings (and is more configurable in other ways).
So I changed the definition of the maven-compiler-plugin
in the pom.xml to:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerId>eclipse</compilerId>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-warn:+boxing,enumSwitch,javadoc,hashCode</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>1.8.2</version>
</dependency>
</dependencies>
</plugin>
In my <reporting>
section, I have:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
</plugin>
So far, so good. I did a mvn clean install
and everything builds fine, all the tests pass, and everything looks great.
But when I try to run mvn site
, when it gets to the Javadoc report, it fails with what appears to be a Javadoc crash:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.0:site (default-site) on project framework: Error during page generation: Error rendering Maven report:
[ERROR] Exit code: 1 - java.lang.StringIndexOutOfBoundsException: String index out of range: -15
[ERROR] at java.lang.String.substring(String.java:1937)
[ERROR] at java.lang.String.substring(String.java:1904)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.simpleBinaryName(ClassReader.java:958)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readEnclosingMethodAttr(ClassReader.java:930)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readMemberAttr(ClassReader.java:909)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readClassAttr(ClassReader.java:1053)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readClassAttrs(ClassReader.java:1067)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readClass(ClassReader.java:1560)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readClassFile(ClassReader.java:1658)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:1845)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:1777)
[ERROR] at com.sun.tools.javac.code.Symbol.complete(Symbol.java:386)
[ERROR] at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:763)
[ERROR] at com.sun.tools.javac.code.Symbol$ClassSymbol.flags(Symbol.java:695)
[ERROR] at com.sun.tools.javadoc.ClassDocImpl.getFlags(ClassDocImpl.java:105)
[ERROR] at com.sun.tools.javadoc.ClassDocImpl.isAnnotationType(ClassDocImpl.java:116)
[ERROR] at com.sun.tools.javadoc.DocEnv.isAnnotationType(DocEnv.java:574)
[ERROR] at com.sun.tools.javadoc.DocEnv.getClassDoc(DocEnv.java:546)
[ERROR] at com.sun.tools.javadoc.PackageDocImpl.getClasses(PackageDocImpl.java:154)
[ERROR] at com.sun.tools.javadoc.PackageDocImpl.addAllClassesTo(PackageDocImpl.java:170)
[ERROR] at com.sun.tools.javadoc.RootDocImpl.classes(RootDocImpl.java:178)
[ERROR] at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.startGeneration(AbstractDoclet.java:96)
[ERROR] at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.start(AbstractDoclet.java:64)
[ERROR] at com.sun.tools.doclets.formats.html.HtmlDoclet.start(HtmlDoclet.java:42)
[ERROR] at com.sun.tools.doclets.standard.Standard.start(Standard.java:23)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:597)
[ERROR] at com.sun.tools.javadoc.DocletInvoker.invoke(DocletInvoker.java:269)
[ERROR] at com.sun.tools.javadoc.DocletInvoker.start(DocletInvoker.java:143)
[ERROR] at com.sun.tools.javadoc.Start.parseAndExecute(Start.java:340)
[ERROR] at com.sun.tools.javadoc.Start.begin(Start.java:128)
[ERROR] at com.sun.tools.javadoc.Main.execute(Main.java:41)
[ERROR] at com.sun.tools.javadoc.Main.main(Main.java:31)
[ERROR]
[ERROR] Command line was: "C:\Program Files (x86)\Java\jdk1.6.0_27\jre\..\bin\javadoc.exe" @options @packages
[ERROR]
[ERROR] Refer to the generated Javadoc files in 'C:\Projects\SMF\framework\target\site\apidocs' dir.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
My Question:
OK, so what changed? All the Javadoc and the Maven site were building just fine when I was using javac, but as soon as I switched to the Eclipse compiler, Javadoc crashes.
Worse, it doesn't even tell me what class caused it to crash, so I don't even know where to begin debugging this.
Obviously, for the time being this means that I'm not going to use the Eclipse compiler, and I'm going to stick with javac instead. But I'm curious as to why this is happening, and what I could possibly do to fix or work around it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
解决方法是为站点目标创建单独的配置文件。这样您就可以为不同的目标定义不同的编译器。
Workaround for this would be to create a separate profile for the site goal. So that you could define different compilers for different goals.
也许 javadoc.exe 没有使用与 Eclipse 使用的 JRE 相同的 JRE。他们是否安装了其他 JRE?尝试手动运行 javadoc.exe 进程并查看它是否执行相同的操作,您可能会获得问题的实际堆栈跟踪。
Maybe the javadoc.exe is not using the same JRE that Eclipse uses. Are their any other JRE's installed? Try running the javadoc.exe process manually and see if it does the same thing, you might get the actual stacktrace of the problem.
这可能不是答案,只是提出一个想法。
将JDK安装在没有空间的文件夹中怎么样(我看到是C:\Program Files (x86)...)。 Java 支持文件名中的空格,但 javadoc 工具可能不支持某些插件/工具/库。
This might not be an answer, but just propose an idea.
How about installing the JDK in the folder without space (I saw it is C:\Program Files (x86)...). Java supports spaces in the file names, but probably some of the plugins/tools/library that javadoc tools just doesn't support it.
我猜测问题是 javac 和 eclipse 使用不同的 JDK 版本来编译代码
Im guessing that the problem is that javac and eclipse are using different JDK versions for compiling your code
我终于有时间再次研究这个问题了。当
javadoc.exe< 运行时,
maven-javadoc-plugin
会在target/site/apidocs
下留下javadoc.bat
脚本。 /code> 进程失败,我可以通过修剪传递到javadoc.exe
的packages
文件中的列表来找到有问题的包。有趣的是,有问题的代码原来是由 Google Protocol Buffers 编译器生成的 Java 源代码。这是幸运的,因为从 Javadoc 中完全排除 protobuf 生成的源代码是可以接受的。
我在 POM 的
和
部分添加了以下定义,这解决了我的问题:I finally got some time to look into this again. The
maven-javadoc-plugin
helpfully leaves behind ajavadoc.bat
script undertarget/site/apidocs
when thejavadoc.exe
process fails, and I was able to find the offending package by pruning the list in thepackages
file that gets passed intojavadoc.exe
.Interestingly, the problematic code turned out to be the Java source generated by the Google Protocol Buffers compiler. This was fortunate, since it's acceptable to simply exclude the protobuf-generated source from the Javadoc entirely.
I added the following definition, under both my
<build>
and<reporting>
sections of the POM, and this resolved my issue: