我正在将我的项目从 Java 6 迁移到 Java 7。我们在项目中广泛使用 JibX。到目前为止,我们使用的是 JibX 1.2.2,一切正常。
但是由于迁移到 Java 7,我们从 JibX 1.2.2 升级到了 JibX 1.2.5。我们也使用 jibx-maven-plugin 版本 1.2.5。但是随着 JibX 的升级,我们现在面临一些问题。
当使用目标 1.7 和 JibX 1.2.5 构建时,JibX 正在构建 jar 文件,但在 aspectJ 编织期间,出现以下错误:
[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.4:compile (default) on project gdsmodel-aspects: Compiler errors:
[ERROR] abort ABORT -- (ClassFormatException) Index 12895 into constant pool (size:12371) is invalid
[ERROR] Index 12895 into constant pool (size:12371) is invalid
[ERROR] org.aspectj.apache.bcel.classfile.ClassFormatException: Index 12895 into constant pool (size:12371) is invalid
[ERROR] at org.aspectj.apache.bcel.classfile.ConstantPool.getConstant(ConstantPool.java:66)
[ERROR] at org.aspectj.apache.bcel.classfile.ConstantPool.getConstantUtf8(ConstantPool.java:220)
[ERROR] at org.aspectj.apache.bcel.classfile.Attribute.readAttribute(Attribute.java:111)
[ERROR] at org.aspectj.apache.bcel.classfile.AttributeUtils.readAttributes(AttributeUtils.java:19)
[ERROR] at org.aspectj.apache.bcel.classfile.FieldOrMethod.<init>(FieldOrMethod.java:97)
[ERROR] at org.aspectj.apache.bcel.classfile.Field.<init>(Field.java:82)
[ERROR] at org.aspectj.apache.bcel.classfile.ClassParser.readFields(ClassParser.java:206)
[ERROR] at org.aspectj.apache.bcel.classfile.ClassParser.parse(ClassParser.java:141)
[ERROR] at org.aspectj.weaver.bcel.Utility.makeJavaClass(Utility.java:467)
[ERROR] at org.aspectj.weaver.bcel.UnwovenClassFile.getJavaClass(UnwovenClassFile.java:68)
[ERROR] at org.aspectj.weaver.bcel.BcelWeaver.addClassFile(BcelWeaver.java:455)
[ERROR] at org.aspectj.weaver.bcel.BcelWeaver.addJarFile(BcelWeaver.java:402)
[ERROR] at org.aspectj.ajdt.internal.core.builder.AjBuildManager.initBcelWorld(AjBuildManager.java:893)
[ERROR] at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performBuild(AjBuildManager.java:249)
[ERROR] at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:185)
[ERROR] at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:112)
[ERROR] at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:60)
[ERROR] at org.aspectj.tools.ajc.Main.run(Main.java:371)
[ERROR] at org.aspectj.tools.ajc.Main.runMain(Main.java:248)
[ERROR] at org.codehaus.mojo.aspectj.AbstractAjcCompiler.execute(AbstractAjcCompiler.java:549)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
[ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
[ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
[ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
[ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:606)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
[ERROR] -> [Help 1]
因此,当 jibx 失败并出现以下错误时,我打开了 jibx-maven-plugin 中的“验证”标志(它指定了“使用 BCEL 验证生成/修改的类的控制标志。”):
[exec] [ERROR] Failed to execute goal org.jibx:jibx-maven-plugin:1.2.5:bind (jibx-bind) on project gdsmodel: Invalid this class index 6218 in constant pool in class file com/g2switch/dto/passive/
JiBX_passive_v24_0MungeAdapter -> [Help 1]
我注意到(并且困扰我)的唯一一件事是 JibX 正在生成一个大小接近 14MB 的“JiBX_passive_v24_0MungeAdapter.class”,并且该类中的验证失败。
[exec] Verification failure on class com.g2switch.dto.passive.JiBX_passive_v24_0MungeAdapter
但是,当我将目标从 1.7 更改为 1.6 时,一切都保持不变,一切正常[也使用 JibX 1.2.5]。
注意:我们有一个项目有很多绑定文件(> 150,而且每个文件都包含大量数据)。构建此项目时出现问题。但是当我包含更少的绑定(< 20)时,问题就消失了。那么这个问题是由于 JibX 生成的大型 munge 适配器文件,当涉及大量绑定时?如果这是原因,那么如何解决呢?