2

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?

2
  • I'm not sure what you mean by "not visible" Commented Jul 20, 2011 at 1:56
  • Is the Javassist-compiled class built at runtime or is it generating a class file that is written back to disk? Commented Jul 20, 2011 at 2:18

1 Answer 1

0

The "classpath" of class B does not depends on how the class is compiled (e.g. 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.