[英]Classpath of classes compiled with Javassist
As the title suggests, what is the classpath of classes compiled with Javassist? 顾名思义,用Javassist编译的类的类路径是什么?
My scenario is: Class A is compiled with Javassist. 我的情况是:A类是使用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... 类B是使用Java Compiler API编译的,并引用了类A。问题是类B对类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. 类B的“类路径”不取决于如何编译类(例如,创建类文件),而是取决于类的加载方式。
Java uses the class loader of a class to look up also all classes which are referenced by this class. Java使用类的类加载器来查找该类引用的所有类。
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. 每个类加载器可以有一个父类加载器,通常loader.loadClass
首先向其父类加载器询问任何类,并在失败的情况下尝试加载类本身。
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
. 因此,只要确保A
类是B类的类加载器可见,这意味着的类加载器A
必须是类的类加载器的父(或父的家长,或......) B
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.