gpt4 book ai didi

java - 在 Java 7 源代码级别编译 GWT 2.6.1

转载 作者:搜寻专家 更新时间:2023-10-31 19:33:14 24 4
gpt4 key购买 nike

我最近将我的 GWT 项目更新到 2.6.1,并开始使用 Java 7 语法,因为 2.6 现在支持 Java 7。

但是,当我尝试编译时,我收到编译器错误,例如

[ERROR] Line 42: '<>' operator is not allowed for source level below 1.7

完整输出

Compiling module com.Project
Validating units:
Ignored 85 units with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
Computing all possible rebind results for 'com.google.gwt.useragent.client.UserAgentAsserter'
Rebinding com.google.gwt.useragent.client.UserAgentAsserter
Checking rule <generate-with class='com.google.gwt.editor.rebind.SimpleBeanEditorDriverGenerator'/>
[WARN] Detected warnings related to 'com.google.gwt.editor.client.SimpleBeanEditorDriver'. Are validation-api-<version>.jar and validation-api-<version>-sources.jar on the classpath?
Specify -logLevel DEBUG to see all errors.
[WARN] Unknown type 'com.google.gwt.editor.client.SimpleBeanEditorDriver' specified in deferred binding rule
[ERROR] Errors in 'file:/C:/workspace/Project/src/com/project/ProjectFile.java'
[ERROR] Line 42: '<>' operator is not allowed for source level below 1.7
[ERROR] Errors in 'file:/C:/workspace/Project/src/com/project/AnotherProjectFile.java'
[ERROR] Line 188: Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted
C:\workspace\Project\build.xml:51: Java returned: 1
at org.apache.tools.ant.taskdefs.Java.execute(Java.java:111)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:809)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.Main.start(Main.java:180)
at org.apache.tools.ant.Main.main(Main.java:268)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:30)
C:\workspace\Project\build.xml:51: Java returned: 1
at org.apache.tools.ant.taskdefs.Java.execute(Java.java:111)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:809)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.Main.start(Main.java:180)
at org.apache.tools.ant.Main.main(Main.java:268)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:30)
C:\workspace\Project\build.xml:51: Java returned: 1
at org.apache.tools.ant.taskdefs.Java.execute(Java.java:111)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:809)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.Main.start(Main.java:180)
at org.apache.tools.ant.Main.main(Main.java:268)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:30)

如何指定 GWT 编译器以 1.7 为目标?我的印象是默认情况下它会这样做,但我想不会。我尝试清理项目,包括删除 gwt-unitCache 目录,但无济于事。

这是我的 Ant 编译目标。

<target name="compile" depends="prepare">
<javac includeantruntime="false"
debug="on"
debuglevel="lines,vars,source"
srcdir="${src.dir}"
destdir="${build.dir}"
source="7"
target="7">
<classpath refid="project.classpath"/>
</javac>
</target>

<target name="gwt-compile" depends="compile">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<!-- src dir is added to ensure the module.xml file(s) are on the classpath -->
<pathelement location="${src.dir}"/>
<pathelement location="${build.dir}"/>
<path refid="project.classpath"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="-sourceLevel"/><arg value="7"/>
<arg value="${gwt.module.name}"/>
</java>
</target>

最佳答案

GWT 编译器(和 SuperDevMode 的代码服务器)有一个 -sourceLevel可用于指定语言级别的参数,类似于 -source javac 的参数.

默认值-sourceLevel取决于您当前的 JVM,因此如果您使用 JDK 1.7,它应该默认为 Java 7。

显式传递 -sourceLevel 7 是一种很好的做法(或 1.7 )到 GWT,anda -source 7 (或 1.7 )到 javac (在你的 source="7" Ant 任务中使用 <javac>)

关于java - 在 Java 7 源代码级别编译 GWT 2.6.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23958028/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com