我们需要将-Xpkginfo:always
参数传递给javac
编译器。我们正在使用javac 1.7.0_25
。说-Xpkginfo
,此版本可用java doc。
package-info.class
个文件javac
编译器崩溃:An exception has occurred in the compiler (1.7.0_25). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.NullPointerException
at com.sun.tools.javac.comp.Enter.visitTopLevel(Enter.java:291)
at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:459)
at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:258)
at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:272)
at com.sun.tools.javac.comp.Enter.complete(Enter.java:484)
at com.sun.tools.javac.comp.Enter.main(Enter.java:469)
at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:929)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
at com.sun.tools.javac.main.Main.compile(Main.java:439)
at com.sun.tools.javac.main.Main.compile(Main.java:353)
at com.sun.tools.javac.main.Main.compile(Main.java:342)
at com.sun.tools.javac.main.Main.compile(Main.java:333)
at com.sun.tools.javac.Main.compile(Main.java:76)
at com.sun.tools.javac.Main.main(Main.java:61)
它与Java 1.8兼容,但是很遗憾,由于我们仍然有旧的Java代码,因此我们无法升级Java编译器。
使用javac -X
来确保1.7.0_25
具有-Xpkginfo
自变量。答案是肯定的:
PS C:\SVN\products\faa_mx\vs2017.install2> javac -X
-Xlint Enable recommended warnings
-Xlint:{all,cast,classfile,deprecation,dep-ann,divzero,empty,fallthrough,finally,options,overrides,path,processing,rawtypes,serial,static,try,unchecked,varargs,-cast,-classfile,-deprecation,-dep-ann,-divzero,-empty,-fallthrough,-finally,-options,-overrides,-path,-processing,-rawtypes,-serial,-static,-try,-unchecked,-varargs,none} Enable or disable specific warnings
-Xbootclasspath/p:<path> Prepend to the bootstrap class path
-Xbootclasspath/a:<path> Append to the bootstrap class path
-Xbootclasspath:<path> Override location of bootstrap class files
-Djava.ext.dirs=<dirs> Override location of installed extensions
-Djava.endorsed.dirs=<dirs> Override location of endorsed standards path
-Xmaxerrs <number> Set the maximum number of errors to print
-Xmaxwarns <number> Set the maximum number of warnings to print
-Xstdout <filename> Redirect standard output
-Xprint Print out a textual representation of specified types
-XprintRounds Print information about rounds of annotation processing
-XprintProcessorInfo Print information about which annotations a processor is asked to process
-Xprefer:{source,newer} Specify which file to read when both a source file and class file are found for an implicitly compiled class
-Xpkginfo:{always,legacy,nonempty} Specify handling of package-info files
[也尝试使用1.7.0_80,相同的崩溃:An exception has occurred in the compiler (1.7.0_80).
java.lang.NullPointerException
at com.sun.tools.javac.comp.Enter.visitTopLevel(Enter.java:291)
at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:459)
at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:258)
at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:272)
at com.sun.tools.javac.comp.Enter.complete(Enter.java:484)
at com.sun.tools.javac.comp.Enter.main(Enter.java:469)
at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:929)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
at com.sun.tools.javac.main.Main.compile(Main.java:439)
at com.sun.tools.javac.main.Main.compile(Main.java:353)
at com.sun.tools.javac.main.Main.compile(Main.java:342)
at com.sun.tools.javac.main.Main.compile(Main.java:333)
at com.sun.tools.javac.Main.compile(Main.java:76)
at com.sun.tools.javac.Main.main(Main.java:61)
使用javac 1.8
和使用命令行javac -source 1.7 -target 1.7 MyClass.java
有意义吗?
在Java 1.7中,如果将-Xpkginfo:always
传递给javac
,则它仅接受package-info.java
空文件。如果您传递非空文件,则会发生崩溃。
使用1.8,javac
可以在一个命令行中处理空文件和非空文件。
因此,1.7的解决方法是多次调用javac
,一次调用所有空的package-info.java
文件,另一次调用非空文件。