简体   繁体   English

AspectJ-编织jdk和非jdk类-NoClassDefFoundError

[英]AspectJ - weaving jdk and non-jdk classes - NoClassDefFoundError

I have three projects setup in eclipse, 我在Eclipse中设置了三个项目,

1) aspects_project - this AspectJ project contains an aspect 'testaspect' I want to weave into certain JDK classes and also the classes within application_project 1)Aspects_project-这个AspectJ项目包含一个方面'testaspect',我想将其编织成某些JDK类以及application_project中的类

2) application_project - this project has aspects_project on its Aspect Path. 2)application_project-该项目在其Aspect Path上具有Aspects_project。

3) jdk_project - this project has aspects_project on its Aspect Path and classes.jar on its InPath. 3)jdk_project-该项目的Aspect Path上具有Aspects_project,而InPath上具有classes.jar。 It is set to output classes_weaved.jar 设置为输出classes_weaved.jar

When I run application_project with classes_weaved.jar preprended to the bootclasspath, the weaved advice in classes of application_project works fine but the advice weaved into the jdk classes gives me the runtime error: 当我将class_weaved.jar预先添加到bootclasspath中运行application_project时,在application_project类中编织的建议可以正常工作,但是编织到jdk类中的建议会给我带来运行时错误:

Exception in thread "main" java.lang.NoClassDefFoundError: testaspect

So the advice weaved into jdk classes cannot find the aspect class that contains the advice. 因此,编织到jdk类中的建议无法找到包含建议的方面类。

Because the classes_weaved.jar is on the bootclasspath you also need to ensure the aspect is visible at that level of the class loader hierarchy. 由于classes_weaved.jar位于bootclasspath上,因此您还需要确保该方面在类加载器层次结构的该级别可见。 The aspect may be on the regular class path but due to class loader visibility rules those jdk classes cannot see it 'down below'. 该方面可能在常规的类路径上,但是由于类加载器可见性规则,那些jdk类无法在“下方”看到它。 You can either ensure the testaspect is placed into the classes_weaved.jar or you can also add the output from the aspects_project to the bootclasspath. 您可以确保将testaspect放置在classes_weaved.jar中,也可以将Aspects_project的输出添加到bootclasspath中。

To do the former (add it to the classes_weaved.jar) I think you could put aspects_project on the inpath (as well as the aspect path) of the jdk_project. 要做前者(将其添加到classes_weaved.jar中),我认为您可以将Aspects_project放在jdk_project的inpath(以及Aspect路径)上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM