阅读:10387回复:0
平台出现Java8的lambda表达式启动报错排除方法
1.平台开发时,自定义java代码使用了jdk8的lambda表达式,启动时报错如下:
Caused by: java.io.IOException: invalid constant type: 18 at com.sunsheen.jfids.javassist.bytecode.ConstPool.readOne(ConstPool.java:1027) at com.sunsheen.jfids.javassist.bytecode.ConstPool.read(ConstPool.java:970) at com.sunsheen.jfids.javassist.bytecode.ConstPool.<init>(ConstPool.java:127) at com.sunsheen.jfids.javassist.bytecode.ClassFile.read(ClassFile.java:723) at com.sunsheen.jfids.javassist.bytecode.ClassFile.<init>(ClassFile.java:110) at org.hibernate.ejb.packaging.AbstractJarVisitor.checkAnnotationMatching(AbstractJarVisitor.java:243) at org.hibernate.ejb.packaging.AbstractJarVisitor.executeJavaElementFilter(AbstractJarVisitor.java:209) at org.hibernate.ejb.packaging.AbstractJarVisitor.addElement(AbstractJarVisitor.java:170) at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:121) at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:129) at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:129) at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:129) at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:129) at org.hibernate.ejb.packaging.ExplodedJarVisitor.doProcessElements(ExplodedJarVisitor.java:87) at org.hibernate.ejb.packaging.AbstractJarVisitor.getMatchingEntries(AbstractJarVisitor.java:146) at org.hibernate.ejb.packaging.NativeScanner.getClassesInJar(NativeScanner.java:128) 2.解决问题需要找到写了labmda语法的Java文件,删除jdk8 Lambda语法。 3.为了快速定位出问题的class文件,将下面的java文件放入工程中,并保持包名一致。 ExplodedJarVisitor.zip 关键代码: private void getClassNamesInTree(File jarFile, String header) throws IOException { File[] files = jarFile.listFiles(); header = (header == null) ? "" : (String.valueOf(header) + "/"); byte b; int i; File[] arrayOfFile = files; for (i = files.length, b = 0; b < i; ) { File localFile = arrayOfFile; if (!localFile.isDirectory()) { String entryName = localFile.getName(); System.out.println("解析class:"+localFile.toURI()); addElement( String.valueOf(header) + entryName, new BufferedInputStream(new FileInputStream(localFile)), new BufferedInputStream(new FileInputStream(localFile))); } else { getClassNamesInTree(localFile, String.valueOf(header) + localFile.getName()); } b++; } } 4.观看控制台打印,保持前打印的class就是出问题的java文件,找到对应java文件修改。 5.删除第3步引入的辅助java. |
|