Search code examples
javadeploymentarchitecturejarear

Java: When to run a server-tier component as daemon JAR, and when to use EAR


Wikipedia describes an Enterprise Archive (EAR) as:

...a file format used by Java EE for packaging one or more modules into a single archive so that the deployment of the various modules onto an application server happens simultaneously and coherently.

But I am still wondering what "logic rules" apply when trying to determine whether to deploy a Java component as a "daemon JAR" or an EAR. By "daemon JAR" I mean a headless, executable JAR that is coded up to listen and communicate over a port, and which lives and runs server side perpetually as any conventional daemon/service.

Obviously, there are benefits to deploying to an application server like JBoss or GlassFish, otherwise EARs and app servers wouldn't exist!

I'm wondering what specific considerations should be accounted for that would help a developer decide how to package/deploy a backend component.


Solution

  • Well, the application servers e.g. take care of all the networking stuff. It's hard to do it in a stable, scalable way, so I strongly recommend to use an application server rather than try and implement your own server.

    EJBs and Web Services become just some POJOs with some annotations. Even DB transactions and security/ access rights can be controlled with just some annotations on EJBs.