At my company we’re starting to use JBoss 7.1 and came across a problem with its new classloading behavior. We’re deploying an EAR with the following structure:
In common.jar are classes included, that have a package-private constructor that should only be used within ejb.jar’s factory. For this the factory and the specific classes are located in the same package, but in different jar’s. So a client can only use the public constructor of the classes whereas the ejb.jar can invoke the internal contructor not visible to the client.
With JBoss 5.1.0 this worked without a problem. But when we tried the same with JBoss 7.1, we encountered the following Error:
Caused by: java.lang.IllegalAccessError: tried to access method CommonClass.<init>()V from class FactoryClass
This is due to the fact that with JBoss 7 each jar is loaded by a separate classloader. We tried the suggested workaround using the jboss-deployment-structure.xml mentioned in a similar JIRA ticket, but always ended up in two separate classloaders for the jar’s.
Since it is a limitation of the underyling JVM and not JBoss 7 we simply added the factory to the common.jar and created a common-client.jar via maven assembly where the factory is excluded. Not nice, but helped us to go on.