使用 GWT 2.6 将 Java 7 升级到 Java 8

Upgrading Java 7 to Java 8 using GWT 2.6

在使用 GWT 2.7 将 Java 7 升级到 Java8 时,我得到以下 Exception.Can 任何人都可以帮助我解决此错误

[ERROR] Source level must be one of [auto, 1.6, 1.7].
[ERROR] Google Web Toolkit 2.6.1
[ERROR] Compiler [-logLevel level] [-workDir dir] [-[no]compileReport] [-X[no]checkCasts] [-X[no]classMetadata] [-[no]draftCompile] [-[no]checkAssertions] [-X[no]closureCompiler] [-XfragmentCount numF
ragments] [-XfragmentMerge numFragments] [-gen dir] [-optimize level] [-[no]saveSource] [-style style] [-[no]failOnError] [-X[no]enforceStrictResources] [-[no]validateOnly] [-sourceLevel [auto, 1.6, 1
.7]] [-localWorkers count] [-war dir] [-deploy dir] [-extra dir] [-saveSourceOutput dir] module[s]
[ERROR]
[ERROR] where
[ERROR]   -logLevel                     The level of logging detail: ERROR, WARN, INFO, TRACE, DEBUG, SPAM, or ALL
[ERROR]   -workDir                      The compiler's working directory for internal use (must be writeable; defaults to a system temp dir)
[ERROR]   -[no]compileReport            Compile a report that tells the "Story of Your Compile". (defaults to OFF)
[ERROR]   -X[no]checkCasts              EXPERIMENTAL: Insert run-time checking of cast operations. (defaults to ON)
[ERROR]   -X[no]classMetadata           EXPERIMENTAL: Include metadata for some java.lang.Class methods (e.g. getName()). (defaults to ON)
[ERROR]   -[no]draftCompile             Compile quickly with minimal optimizations. (defaults to OFF)
[ERROR]   -[no]checkAssertions          Include assert statements in compiled output. (defaults to OFF)
[ERROR]   -X[no]closureCompiler         EXPERIMENTAL: Compile output Javascript with the Closure compiler for even further optimizations. (defaults to OFF)
[ERROR]   -XfragmentCount               EXPERIMENTAL: Limits of number of fragments using a code splitter that merges split points.
[ERROR]   -XfragmentMerge               DEPRECATED (use -XfragmentCount instead): Enables Fragment merging code splitter.
[ERROR]   -gen                          Debugging: causes normally-transient generated types to be saved in the specified directory
[ERROR]   -optimize                     Sets the optimization level used by the compiler.  0=none 9=maximum.
[ERROR]   -[no]saveSource               Enables saving source code needed by debuggers. Also see -debugDir. (defaults to OFF)
[ERROR]   -style                        Script output style: OBF[USCATED], PRETTY, or DETAILED (defaults to OBF)
[ERROR]   -[no]failOnError              Fail compilation if any input file contains an error. (defaults to OFF)
[ERROR]   -X[no]enforceStrictResources  EXPERIMENTAL: Avoid adding implicit dependencies on "client" and "public" for modules that don't define any dependencies. (defaults to OFF)
[ERROR]   -[no]validateOnly             Validate all source code, but do not compile. (defaults to OFF)
[ERROR]   -sourceLevel                  Specifies Java source level (defaults to auto:1.7)
[ERROR]   -localWorkers                 The number of local workers to use when compiling permutations
[ERROR]   -war                          The directory into which deployable output files will be written (defaults to 'war')
[ERROR]   -deploy                       The directory into which deployable but not servable output files will be written (defaults to 'WEB-INF/deploy' under the -war directory/jar, and may be the sam
e as the -extra directory/jar)
[ERROR]   -extra                        The directory into which extra files, not intended for deployment, will be written
[ERROR]   -saveSourceOutput             Overrides where source files useful to debuggers will be written. Default: saved with extras.
[ERROR] and
[ERROR]   module[s]                     Specifies the name(s) of the module(s) to compile
[INFO] ------------------------------------------------------------------------
...

GWT 2.6 是否与 Java 8 兼容?

错误告诉你:

[ERROR] Source level must be one of [auto, 1.6, 1.7].

GWT 将支持 Java8 从版本 2.8 开始。

如果无法升级GWT版本,需要在项目中指定编译的源级别pom.xml

<properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
</properties>
[ERROR] Source level must be one of [auto, 1.6, 1.7].
[…]
[ERROR]   -sourceLevel                  Specifies Java source level (defaults to auto:1.7)

明确地将 -sourceLevel 设置为 1.7(或 1.6)。

可以使用 org.codehaus.mojo:gwt-maven-plugin 配置中的 <sourceLevel>1.7</sourceLevel> 或将 maven.compiler.source 属性 设置为 [=12] =](这也将配置 maven-compiler-plugin)。请参阅 http://mojo.codehaus.org/gwt-maven-plugin/compile-mojo.html#sourceLevel 了解 org.codehaus.mojo:gwt-maven-plugin。