2

I want to build and deploy my first Java EE 6 multi-tier application, with web and business tiers running on separate physical servers on Glassfish 3.1.

I think I understand what's required from a theoretical hi-level view but am not clear on the specifics and small details.

My current plan as is follows:

  • Create a Maven Enterprise Application in NetBeans 7.
  • Expose Session Facade EJBs via remote interface.
  • Have JSF Backing Beans utilise Session Facade EJBs via JNDI lookup.
  • Deploy EJB JAR to one server and web WAR to the other.

I'd really appreciate some pointers on:

  • Application structure.
  • Correct JNDI lookup with separate servers. Is injection possible?
  • Building appropriate archives.
  • Deployment configuration to allow tiers to communicate.
vkraemer
  • 9,864
  • 2
  • 30
  • 44
retrodev
  • 2,323
  • 6
  • 24
  • 48

2 Answers2

3

Unless you know you will be serving many requests per second, or have very data and/or CPU-heavy business logic, then you should be perfectly fine starting out by deploying both tiers on the same application server. Starting out by deploying to a single Glassfish application server using local interfaces lets you skip a lot of complexity in the runtime environment.

This in turn will allow you to use the simplest form of @EJB-injection in the web tier to access the session facades in the business tier. Local intefaces are faster because the application server can pass references rather than RMI proxies between the tiers and it lets you skip the JNDI lookups. You can always change the annotation later on, or introduce remote interfaces if you later find other reasons to deploy the tiers on separate servers.

Glassfish supports clustering, so you might never have to explicitly separate the two tiers--it all depends on the actual usage patterns, so performance monitoring is key.

Deploying the web tier as a WAR and the business logic as an EJB jar is the right thing to do. Depending on the size and the logical structure of your application, you might want to break that down into to multiple modules.

Maven takes care of building the archives. Make sure you define a sub-project for each war and jar archive, plus a sub-project for assembling the EAR-file. The latter project will pull in the war and jar files produced by the other sub-projects. String all the projects together with a master maven project and voila, you have the flexibility to build each component separately, build the entire thing, or any combination in-between.

Kim Burgaard
  • 3,508
  • 18
  • 11
  • From the looks of it, most people suggest I deploy both tiers to the same server and then use Glassfish clustering to hide the separation if I really need more servers. In this case, is separating the tiers into separate WAR and JAR still preferable to just using a single WAR? – retrodev May 31 '11 at 09:45
  • Yes. The web tier is deployed to a web container, and the business tier is deployed to an EJB container, so the separate packaging both reflects separation in the logical, development and deployment domains. – Kim Burgaard May 31 '11 at 13:10
2

You have chosen a hard path, as others have pointed out in comments and answers...

Let's start with the structure of your app(s). You are going to end up with four achives... two that you will deploy:

  1. a "regular" jar for the Remote interface of your EJB (jar-of-interfaces)

  2. an EJB jar that has the implementation of your EJB

  3. an EAR archive that will contain the jar-of-interfaces (in the /lib subdirectory) and the EJB jar (in the 'root').

  4. a WAR file that contains the code that uses the Remote interface of your EJB. This will have the jar-of-interfaces in WEB-INF/lib.

The rest of this answer is based on the EJB FAQ. The most applicable part of that document is here.

You can inject the EJB into the ManagedBean. You will not need to use a dot-lookup method in your ManagedBean.

You will need to use the corbaname for your bean in the glassfish-web.xml file.

vkraemer
  • 9,864
  • 2
  • 30
  • 44
  • I understand this will be difficult, but I'm doing it as a learning exercise so that I can better understand how things work. The links were extremely helpful, thank you. – retrodev May 31 '11 at 09:48