1. 程式人生 > >ASM ClassReader failed to parse class file- probably due to a new Java class file version that isn't supported yet問題

ASM ClassReader failed to parse class file- probably due to a new Java class file version that isn't supported yet問題

也好 報錯 總結 org maven idt 文件 caused img

出錯情況:由於接口的更改,在工程中更新了一個外部依賴的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文件進行編譯。

下次在引入別人包的時候是需要謹慎的,稍不註意,後續的排錯,更改是非常耗時耗力的。不過在職業前期累計錯誤也好,之後看到錯誤就直到“對癥下藥”了。

ASM ClassReader failed to parse class file- probably due to a new Java class file version that isn't supported yet問題