This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes EJB and other Java EE Technologies and the fly likes Multiple war in an ear file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Multiple war in an ear file" Watch "Multiple war in an ear file" New topic
Author

Multiple war in an ear file

nand rai
Greenhorn

Joined: Feb 17, 2009
Posts: 27

how do we configure multiple war files in a ear file? if we break the webapp to into multiple war files, what will happen to session and security setup.

I have a big application in a single Ear, single war file. i want to have multi war, single ear file.


Thanks
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1


There's no problem with multiple wars. That's pretty much standard packaging.

But not all resources are shared across separate war files. Each has a separate context root, and session sharing between war files is not allowed by the standard, although I know IBM had some 'extensions' that did allow you to share session data between war files.

Here's a little something I wrote on the subject from a few years back:

Why Would You Put Multiple War Files in a J2EE EAR?


Why would an ear file have more than one web module?

An ear file can contain any number of web and ejb modules. This begs the question, “should I deploy all of my web content in a common war file, or should I separate my web content into separate war files?”

Well, application partitioning is an inexact science, but there are some rules we can follow.

Take for instance a scenario where your enterprise application provides web access for both your human resources (hr) and accounting departments. Should this web application be separated into an accounting.war and hr.war file, or should everything be packaged together into a single hraccounting.war file?

When it comes to application packaging, there are no ‘right answers.’ There are only ‘wrong answers.’ The best we can do is try not to get the wrong answer.

Here are a few important points to consider when developing and subsequently deploying an application.

The Session Problem

Sessions, a mechanism for storing transient information about the client interacting with your website, are not shared across war files. If session information needs to be shared amongst hr and accounting modules, splitting your Servlets and JSPs across multiple war files is going be a problem.



The Common ServletContext

Servlets and JSPs can share information between each other by using a special scope named the ServletContext. If you are placing information in this ServletContext, such as the IP address of the accounting database, you probably don’t want you’re hr application to be able to access it.

The ServletContext is not shared between war files. If you do not want one set of Servlets to see another set of Servlets ServletContext, you’re going to have to separate the two applications into separate war files.

Forwarding to a JSPs

A common design pattern is to have a Servlet handle a request, and have it forward to a JSP for display. However, Servlets can only forward to JSPs packaged inside of a common war. You can use a special method called ‘redirect’ to send a user to a JSP in a different web module, but the redirection becomes a brand new request, and information about the initial request and response is lost.

Managabitly

Manageability of your applications must always be a prime concern. The cost of any application is not how much money is require to develop it, or the hardware required to run it, but is instead the cost of managing that application over the long-term.

If the two applications you are packaging are large, separating them into two separate war files would make them much easier to manage. Modularity helps facilitate maintainability



Why Would You Put Multiple War Files in a J2EE EAR?

-Cameron McKenzie

suresh dasari
Ranch Hand

Joined: Oct 05, 2009
Posts: 121

Could you please explain how should I do that?
I mean I want to generate an EAR file with 2 war files in it.


Sun Certified Java Programmer with 93 percent
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Which development tool are you using? Most development tools will do it for you.
suresh dasari
Ranch Hand

Joined: Oct 05, 2009
Posts: 121

RSA 7.5
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

Hi..

I think it doesn't matter many WAR/JAR files in an EAR..
we could unite all of it..
but, the issue that we've to consider is the deployment time..
the deployment time needs longer time, and sometimes its a bit difficult to maintained..

What the RSA stands for?..
its abbreviation is strength for me..


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
suresh dasari
Ranch Hand

Joined: Oct 05, 2009
Posts: 121

Rational Software Archetecht
 
wood burning stoves
 
subject: Multiple war in an ear file