Aspectj 在 Class 重定位后抛出 "org.aspectj.weaver.BCException: malformed org.aspectj.weaver.PointcutDeclaration attribute" 异常

Aspectj throws "org.aspectj.weaver.BCException: malformed org.aspectj.weaver.PointcutDeclaration attribute" exception after Class Relocation

我在我正在进行的项目中使用 AspectJ。 作为项目的一部分,我试图使用 "maven-shade-plugin" 和 "jarjar-maven-plugin" 将 类 从一个罐子转移到另一个罐子。

在这两种情况下,当我尝试使用生成的 JAR 时,AspectJ 失败并出现以下异常:

    Jan 12, 2016 7:18:52 PM org.aspectj.weaver.tools.Jdk14Trace error
SEVERE: register definition failed
java.lang.RuntimeException: Problem processing attributes in io.myproject.MyAspect
    at org.aspectj.weaver.bcel.BcelObjectType.ensureAspectJAttributesUnpacked(BcelObjectType.java:387)
    at org.aspectj.weaver.bcel.BcelObjectType.<init>(BcelObjectType.java:162)
    at org.aspectj.weaver.bcel.BcelWorld.buildBcelDelegate(BcelWorld.java:410)
    at org.aspectj.weaver.bcel.BcelWorld.resolveDelegate(BcelWorld.java:405)
    at org.aspectj.weaver.ltw.LTWWorld.resolveDelegate(LTWWorld.java:107)
    at org.aspectj.weaver.World.resolveToReferenceType(World.java:478)
    at org.aspectj.weaver.World.resolve(World.java:319)
    at org.aspectj.weaver.bcel.BcelWeaver.addLibraryAspect(BcelWeaver.java:159)
    at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.registerAspects(ClassLoaderWeavingAdaptor.java:485)
    at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.registerDefinitions(ClassLoaderWeavingAdaptor.java:304)
    at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.initialize(ClassLoaderWeavingAdaptor.java:171)
    at org.aspectj.weaver.loadtime.Aj$ExplicitlyInitializedClassLoaderWeavingAdaptor.initialize(Aj.java:340)
    at org.aspectj.weaver.loadtime.Aj$ExplicitlyInitializedClassLoaderWeavingAdaptor.getWeavingAdaptor(Aj.java:345)
    at org.aspectj.weaver.loadtime.Aj$WeaverContainer.getWeaver(Aj.java:319)
    at org.aspectj.weaver.loadtime.Aj.preProcess(Aj.java:113)
    at org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter.transform(ClassPreProcessorAgentAdapter.java:54)
    at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
    at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access0(URLClassLoader.java:73)
    at java.net.URLClassLoader.run(URLClassLoader.java:368)
    at java.net.URLClassLoader.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
Caused by: org.aspectj.weaver.BCException: malformed org.aspectj.weaver.PointcutDeclaration attribute (length:530)org.aspectj.weaver.BCException: Bad type signature log


    at org.aspectj.weaver.AjAttribute.read(AjAttribute.java:137)
    at org.aspectj.weaver.bcel.Utility.readAjAttributes(Utility.java:101)
    at org.aspectj.weaver.bcel.BcelObjectType.ensureAspectJAttributesUnpacked(BcelObjectType.java:383)
    ... 30 more

[AppClassLoader@14dad5dc] warning register definition failed -- (RuntimeException) Problem processing attributes in io.myproject.MyAspect
Problem processing attributes in io.myproject.MyAspect
java.lang.RuntimeException: Problem processing attributes in io.myproject.MyAspect
    at org.aspectj.weaver.bcel.BcelObjectType.ensureAspectJAttributesUnpacked(BcelObjectType.java:387)
    at org.aspectj.weaver.bcel.BcelObjectType.<init>(BcelObjectType.java:162)
    at org.aspectj.weaver.bcel.BcelWorld.buildBcelDelegate(BcelWorld.java:410)
    at org.aspectj.weaver.bcel.BcelWorld.resolveDelegate(BcelWorld.java:405)
    at org.aspectj.weaver.ltw.LTWWorld.resolveDelegate(LTWWorld.java:107)
    at org.aspectj.weaver.World.resolveToReferenceType(World.java:478)
    at org.aspectj.weaver.World.resolve(World.java:319)
    at org.aspectj.weaver.bcel.BcelWeaver.addLibraryAspect(BcelWeaver.java:159)
    at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.registerAspects(ClassLoaderWeavingAdaptor.java:485)
    at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.registerDefinitions(ClassLoaderWeavingAdaptor.java:304)
    at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.initialize(ClassLoaderWeavingAdaptor.java:171)
    at org.aspectj.weaver.loadtime.Aj$ExplicitlyInitializedClassLoaderWeavingAdaptor.initialize(Aj.java:340)
    at org.aspectj.weaver.loadtime.Aj$ExplicitlyInitializedClassLoaderWeavingAdaptor.getWeavingAdaptor(Aj.java:345)
    at org.aspectj.weaver.loadtime.Aj$WeaverContainer.getWeaver(Aj.java:319)
    at org.aspectj.weaver.loadtime.Aj.preProcess(Aj.java:113)
    at org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter.transform(ClassPreProcessorAgentAdapter.java:54)
    at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
    at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access0(URLClassLoader.java:73)
    at java.net.URLClassLoader.run(URLClassLoader.java:368)
    at java.net.URLClassLoader.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
Caused by: org.aspectj.weaver.BCException: malformed org.aspectj.weaver.PointcutDeclaration attribute (length:530)org.aspectj.weaver.BCException: Bad type signature log


    at org.aspectj.weaver.AjAttribute.read(AjAttribute.java:137)
    at org.aspectj.weaver.bcel.Utility.readAjAttributes(Utility.java:101)
    at org.aspectj.weaver.bcel.BcelObjectType.ensureAspectJAttributesUnpacked(BcelObjectType.java:383)
    ... 30 more

如果你能指出我做错了什么,我将不胜感激。

谢谢, 纳达夫

最后我没有使用maven-jarjar-plugin和maven-shade插件。我使用了 JarJar 的 JAR 本身,这解决了问题(因为它在编译期间不使用 AspectJ 修改 JAR)。

以下问题的答案描述了解决方案: