简体   繁体   中英

Classpath of classes compiled with Javassist

As the title suggests, what is the classpath of classes compiled with Javassist?

My scenario is: Class A is compiled with Javassist. Class B is compiled with Java Compiler API and references Class A. The problem is that Class A is not visible to Class B...

Any ideas?

The "classpath" of class B does not depends on how the class is compiled (eg the class file is created), but how the class is loaded.

Java uses the class loader of a class to look up also all classes which are referenced by this class.

Each class loader can have a parent class loader, and normally loader.loadClass first asks its parent class loader about any classes, and in case of failure tries to load the class itself.

Thus, simply make sure the A class is visible to the class loader of class B, meaning that the class loader of A must be a parent (or parent of parent, or ...) of the class loader of class B .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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