And yet again, response will be the same.
create global module and make sure you create jandex indexes for it. and than when you are adding dependency to the global module make sure you also include indexes with it.
in short is it just matter of preparing your module properly and use it.
Thanks Tomaz. I will test it. Do you know if it's supported also to have the persistence.xml in the module?
Persistence.xml files are not deployed in global modules. To share persistence units between deployments, internal service dependencies are needed on the persistence. In other words, internal code changes are needed to accommodate this.
For example, if you have commonPU.jar deployed with the entity classes + persistence.xml, your other deployments that depend on commonPU.jar would have these dependencies set so that if commonPU.jar is redeployed, the other deployments would also restart. There is also the sharing of the commonPU.jar classes that needs to work (including the enhancing/rewriting of entity classes). The clustering of the JPA second level cache might also need work.
The global JNDI (jboss.entity.manager.factory.jndi.name/jboss.entity.manager.jndi.name) option that you mentioned, doesn't add the internal service dependency that I mentioned above. So, if the deployment that contains the persistence.xml (with jboss.entity.manager.factory.jndi.name) is undeployed, the EntityManagerFactory will no longer be available in JNDI but dependent applications will not be aware. The typical use of the global JNDI (jboss.entity.manager.factory.jndi.name/jboss.entity.manager.jndi.name) is for use within the same application (it does not setup the sharing of entity classes across deployments).
When you say internal code changes are needed to accomodate this, do you mean WildFly internal code changes, don't you? Or in other words, that it's not supported at the moment, is it?
There is currently no way to setup the dependencies between deployments that you would need to share persistence units between deployments. If your just sharing classes via a global module (like you asked about originally), you don't get to share a persistence unit but there are no dependencies issues (each deployment will need its own persistence.xml).