zoukankan      html  css  js  c++  java
  • ASM ClassReader failed to parse class file- probably due to a new Java class file version that isn't supported yet问题

    出错情况:由于接口的更改,在工程中更新了一个外部依赖的jar包,在编译启动后遇到了下述问题:

    Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new
    Java class file version that isn't supported yet: URL [jar:file:/D:/project/extra-v20171116/extra/extra-interfaces/target/
    extra/WEB-INF/lib/seat-api-1.0.jar!/com/csair/extra/seat/controller/paramswrapper/FlightChangeReqParam.class];
    nested exception is java.lang.IllegalArgumentException

    排错:根据probably due to a new Java class file version that isn't supported yet这条提示消息,感觉可能是jdk的匹配问题。

                  然后我查看了一下项目工程所使用的jdk版本。----在项目的pom文件中

    				<!-- maven 编译版本使用jdk1.7 -->
    				<plugin>
    					<artifactId>maven-compiler-plugin</artifactId>
    					<version>3.1</version>
    					<configuration>
    						<source>1.7</source>
    						<target>1.7</target>
    						<encoding>UTF-8</encoding>
    					</configuration>
    				</plugin>
    

              然后查看一下jar包中报错的FlightChangeReqParam.class的编译版本。通过IDEA直接按住ctrl键点进去看,IDEA会直接帮我们反编译的。

          可以看到这是jdk1.8版本下编译的。所以确实是跟当前的工程不匹配的。应该只要重新打个1.7版本的jar包就不会报错了。

          试着在网上查找一下更深层次的原因。

    If you encounter this error even if you compile with -target 1.7, please note that this is because of a bug in Spring Framework
    which causes ASM classreader to load jdk classes (java.* or javax.*), which are, of course, compiled with -target 1.8. This, combined with the old ASM version in spring 3.2.8 and below, which does not support parsing of 1.8 class files, can also
    lead to this error. This should be fixed in Spring Framework version 3.2.9, which is due to be released soon. Of course, upgrading to Spring Framework 4 will also resolve the issue, as it already contains a newer version of ASM.

    原因:所以其实是Spring3.2.8版本及其以下不支持编译版本为JDK1.8的jar包。如果想要用1.8版本的jar包,那么就得更新到Spring 4。

                 要么就只有全使用编译版本为JDK1.7的jar包。

    总结: 这里还有一个需要注意的地方就是,编译和运行是两个分开的动作。即编译和运行可以使用不同版本的jdk.

               但是需要注意的是:运行的jdk版本不能低于编译时的版本。

               这是因为IDEA中我的jdk版本是1.8的,但是在此之前都是能运行这个工程的。这个不会对工程有影响的。

               由于这是个大工程,有很多人一起开发,因此配置是必须保持稳定的,所以这种情况只能去重修对class文件进行编译。

               下次在引入别人包的时候是需要谨慎的,稍不注意,后续的排错,更改是非常耗时耗力的。不过在职业前期累计错误也好,之后看到错误就直到“对症下药”了。

  • 相关阅读:
    中级实训Android学习记录——百度地图API显示定位
    中级实训Android学习记录——Android Studio工程配置并进行地图显示
    中级实训Android学习记录——百度地图API获取AK
    unity 3d 八、粒子系统与流动效果
    中级实训Android学习记录——项目3制作
    中级实训Android学习记录——RecyclerView、Android存储
    中级实训Android学习记录——项目1、2重铸记录
    裴蜀定理
    二分模板
    最短路问题
  • 原文地址:https://www.cnblogs.com/bocurry/p/7801853.html
Copyright © 2011-2022 走看看