classfile.ClassFormatException

项目加了十几行代码后,tomcat启动时候抛出一个异常

 org.aspectj.apache.bcel.classfile.ClassFormatException: File: 'filename': Invalid byte tag in constant pool: 18
at org.aspectj.apache.bcel.classfile.ClassParser.readConstantPool(ClassParser.java:192)
at org.aspectj.apache.bcel.classfile.ClassParser.parse(ClassParser.java:131)

想着我并没有做什么修改,以为环境问题,clean,重启均无效。后来仔细看下错误,classformatexception,想着会不会语法出问题了,但是编译是通过。看着下面classParser,是对字节码的解析出错了。仔细看了我新增的代码,用了lambda表达式,于是去掉,重试,成功运行了。
最终由org.aspect的包,追根溯源,原来是其他人在项目引用了aspect包,但是版本较低,不支持jdk8语法,升级版本即可兼容。
后来一个小建议:
1. aspect是用于aop。但是spring 有这个包的。我们项目已经有spring。就用spring自带的即可

在查错google的过程中,也发现还有一个类似的错误。

org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 15

不细看以为一样,这个是tomcat引起的。原因也类似,是tomcat7对java8的支持bug。这个bug在tomcat7的较高版本已经修复了。不过我一直喜欢用较高的版本,最好还是使用tomcat8吧。

你可能感兴趣的:(java)