I see. Well, this is a more complicated scenario. First of all, test-jar and test-war are de-facto two separated applications/modules. The way you declare the dependency is WildFly-specific. The portable way requires "Extension Mechanism Architecture" (see also EE.8.2.2 Installed Libraries). Nevertheless, this should work too. And in fact, it works from the class loading perspective. The CDI spec is clear that the container searches for beans in all referenced bean archives.
The problem is that:
A persistence unit that is defined at the level of an EJB-JAR is scoped to that EJB-JAR...
(JPA spec, 8.2.2 Persistence Unit Scope)
Note that Weld does not even recognize ShopDAO as a session bean because it does not see its EJB descriptor. Now the question is whether the "Library Support" only means access to referenced classes and resources or classes, resources and other services (PU, EJBs, etc.). I believe it's the former.
Using this mechanism a Java EE JAR file can reference utility classes or other shared classes or resources packaged in a separate .jar file or directory that is included in the same Java EE application package, or that has been previously installed in the Java EE containers.
(EE spec, EE.8.2 Library Support)
|