我在尝试编译gwt项目时遇到一个错误,该错误通常是由jre 1.7(51.0)编译的类引起的。我已经验证了我的类是用1.6版本编译的。我几乎肯定这是类路径中包含的其他类,但在调试maven构建时,我无法让gwt编译器中断。我正在使用eclipse尝试中断调试maven构建,并为UnsupportClassVersionError和UnableToCompleteException添加断点,但当这种情况发生时,jvm并没有停止。我猜测GWT编译器可能是在一个单独的进程下运行的,我将无法轻松捕捉到这些异常。任何建议都将不胜感激。我宁愿找到一种打破gwt异常的方法,但如果有人知道GIN为什么抱怨无效的类修订,那也太好了。
以下是我尝试使用maven从命令行编译时的错误。
[INFO] --- gwt-maven-plugin:2.5.1:compile (default) @ smartbar ---
[INFO] Loading inherited module 'com.smartbar.SmartBar'
[INFO] Loading inherited module 'com.smartbar.SmartBarCommon'
[INFO] Loading inherited module 'com.google.gwt.inject.Inject'
[INFO] [ERROR] Unexpected error while processing XML
[INFO] java.lang.UnsupportedClassVersionError: com/google/gwt/inject/rebind/GinjectorGenerator : Unsupported major.minor version 51.0
[INFO] at java.lang.ClassLoader.defineClass1(Native Method)
[INFO] at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
[INFO] at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
chinshaw$ java -version
java version "1.6.0_51"
Java(TM) SE Runtime Environment (build 1.6.0_51-b11-457-11M4509)
Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-457, mixed mode)
chinshaw$ find . -name '*.class' | xargs file | head -10
./WEB-INF/classes/com/testing/client/activity/AbstractActivity.class: compiled Java class data, version 50.0 (Java 1.6)
./WEB-INF/classes/com/testing/client/activity/EstablishmentInventoryActivity.class: compiled Java class data, version 50.0 (Java 1.6)
./WEB-INF/classes/com/testing/client/activity/EstablishmentNavigationActivity.class: compiled Java class data, version 50.0 (Java 1.6)
./WEB-INF/classes/com/testing/client/ClientUserSession.class: compiled Java class data, version 50.0 (Java 1.6)
./WEB-INF/classes/com/testing/client/events/EntityEditEvent$Handler.class: compiled Java class data, version 50.0 (Java 1.6)
./WEB-INF/classes/com/testing/client/events/EntityEditEvent.class: compiled Java class data, version 50.0 (Java 1.6)
./WEB-INF/classes/com/testing/client/events/InventoryItemSelectionEvent$Handler.class: compiled Java class data, version 50.0 (Java 1.6)
./WEB-INF/classes/com/testing/client/events/InventoryItemSelectionEvent.class: compiled Java class data, version 50.0 (Java 1.6)
./WEB-INF/classes/com/testing/client
临时解决方案
这可能只是maven存储库的问题,但2.1.0 gin包似乎是用1.7.0构建的。我将依赖关系降级到2.0.0,现在运行良好。
desktop-mini:2.1.0 chinshaw$ pwd
/Users/chinshaw/.m2/repository/com/google/gwt/inject/gin/2.1.0
desktop-mini:inject chinshaw$ find . -name '*.class' -exec file {} ; | head -10
./client/AbstractGinModule.class: compiled Java class data, version 51.0
./client/assistedinject/BindingCollector.class: compiled Java class data, version 51.0
./client/assistedinject/FactoryModule.class: compiled Java class data, version 51.0
./client/assistedinject/GinFactoryModuleBuilder.class: compiled Java class data, version 51.0
./client/AsyncProvider.class: compiled Java class data, version 51.0
./client/binder/GinAnnotatedBindingBuilder.class: compiled Java class data, version 51.0
./client/binder/GinAnnotatedConstantBindingBuilder.class: compiled Java class data, version 51.0
./client/binder/GinAnnotatedElementBuilder.class: compiled Java class data, version 51.0
./client/binder/GinBinder.class: compiled Java class data, version 51.0
./client/binder/GinConstantBindingBuilder.class: compiled Java class data, version 51.0
这是bug id,真希望我先看一下。不过,先假设是另一个罐子出了问题。http://code.google.com/p/google-gin/issues/detail?id=190
enforceBytecodeVersion Enforcer规则应该能够帮助您解决此类问题。它将遍历所有依赖项,以检查它们是否与所需的类版本匹配。