Search code examples
javaclassloaderwildflyear

wildfly classloader issue between war's lib and ear's lib


I've this schema for an EAR deployed in Wildfly:

  • EAR:
    • ejbA.jar
    • ejbB.jar
    • lib
      • LibInterfaceA.jar
      • LibInterfaceB.jar
    • WAR
      • lib
        • LibInterfaceA.jar

LibInterfaceA.jar is a library of only interfaces used in ejb modules (A adn B) and in WAR for injecting ejb and extended in LibInterfaceB.jar .

The problem is with java reflection when I search for custom annotations inside LibInterfaceA:

public Annotation getAnnotazione(Method method, Class annotationType){
    Annotation annotazioni[] = method.getAnnotations();
    URL locationsearch = annotationType.getResource('/' + annotationType.getName().replace('.', '/') + ".class");
    for(Annotation a : annotazioni){
        Class klass = a.annotationType();
        URL location = klass.getResource('/' + klass.getName().replace('.', '/') + ".class");
        if(a.annotationType().getName().equals(annotationType.getName())){
            return a;
        }
    }
    return null;
}

I call this method in a class inside the WAR to find the annotation annotationType=@Custom. @Custom is of WAR/lib/LibInterfaceA.jar

If i call this method to find on a Class implementing a LibInterfaceB's interface that extends an interface in LibInterfeceA, the annotation @Custom on the method is of the jar EAR/lib/LibInterfaceA.jar , so the classes are different for classloading problem.

How can I solve this problem?


Solution

  • You can remove LibInterfaceA.jar from war. By default sub deployments of ear can use its lib directory (unless you set ear-subdeployments-isolated = true in jboss-depoyment-structure.xml of ear)