There are two primary differences highlighted in section 15.4 of the EJB 3.1 specification:
- All EJBs in a WAR share the component namespace (
java:comp
) with the WAR and all other EJBs in the WAR. Normally, each EJB has its own component namespace. This makes it easier to share reference names and bindings (though this can be done explicitly in EE 6 withjava:module
orjava:app
), but it increases the chance of conflict in a large WAR. - EJB classes are loaded by the WAR class loader. In practice, this doesn't matter much, it's just something to be aware of if you encounter class loading problems.
If you want to use an EJB as a REST service, you must package the EJB in the WAR. If you're concerned about "duplicating" EJB logic inside the WAR and for an EJB module, you could declare a base class in the EJB module, and then declare subclasses in the WAR and EJB modules that extend the base class and are annotated @Stateless
or @Singleton
.