But this doesn't explain why NoClassDefFoundError happens.
OK, I see your problem.
The reason why B is not found in A is b/c of the way we deploy deployers/ vs. deploy.
ProfileService in AS, deploys different parts of AS libs in different phases.
(1) bootstrap phase -- conf/bootstrap/ dir
(2) deployers/
(3) deploy/
So, at the time your A class in deployers/a.jar is deployed, B class in deploy/b.jar is not yet deployed,
hence no matching classloader.
If you would lazy load A, only checking B when you know it's gonna be available, it would be OK.
When is contextClassLoader of current thread set in JBoss5?
Different sub-systems set if differently.
If you're asking about deployes/VDF, then the answer is DeployerWrapper class.