aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Packaging an EAR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Packaging an EAR" Watch "Packaging an EAR" New topic
Author

Packaging an EAR

Elizabath Lima
Ranch Hand

Joined: Nov 23, 2005
Posts: 32
Hi,

I'm a novice to EJB. I need help to package my classes to an ear to deploy in jboss. I'm using mysql as back end. I'm a bit confused in packaging the appication into jar,war and ear.

In my appliction there is jsps (in web folder) interacting with servlet (servlet folder) and the servlet does lookups for EJB (in ejb folder).EJB in turn reffer DAO classes in (dao folder). This is the flow.

How i can do packaging of all these folders? I mean which folders i need to put in jar and in war?

And in some cases the look up is "java:comp/env/ejb/Hello" and in other just "ejb/Hello" that is the JNDI name.. wat is the difference.. How i can make the lookup string like "java:comp/env..."
Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
You have to pack your ejbs in the jar file and web components in the war, then you have to create an ear file using .jar and .war file.

About lookup string both will do the job, the first one is absolute one. even if you are not giving the whole path JNDI will prefix java:comp/env/, you may use any one of that better use the absolute one.
Rajesh Agarwal
Ranch Hand

Joined: Aug 01, 2005
Posts: 79
Also the EAR should have an application.xml which would contain details about the war, jar packed inside the ear
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Lima,


And in some cases the look up is "java:comp/env/ejb/Hello" and in other just "ejb/Hello" that is the JNDI name.. wat is the difference.. How i can make the lookup string like "java:comp/env..."

You basically lookup components using the syntax "java:comp/env/" when ejb references are specified. This is a very good practice when using EJBs though. Google the net for Environment Naming Context (ENC) if you want a better understanding. The "ejb/Hello" syntax look up the component using its jndi global name.
Regards.


I think, therefore I exist -- Rene Descartes
Elizabath Lima
Ranch Hand

Joined: Nov 23, 2005
Posts: 32
Hi

Thanks for all hands giving a ranch hand..

I would like to know about the class's factor which determines where to put the class in an ear either in jar or war?
In jar, are we privileged only to put the bean and two interfaces of any EJB?

Where we will put .properties file in an ear? and how we can give path in java class to read the .properties file? In my application i put it directly in .war and it is not taking the path FileInputStream("/fileName.properties");
How i can give path ?

Where we will put a class (ClassA) which does look up for EJB and invokes a business method and a class (ClassB) which is invoked by a method in EJB ?

Hope i'm successfull in expressing the scenario..

Thanks,
Lima
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Lima,

There is no short answer to your question(s). I�d advice you to first understand all basic concepts regarding packing j2ee application and also try to understand your container�s classloading architecture.
To make long story short, you use jar for packing ejbs, war for packing web applications and ear for packing enterprise applications. Can you pack and deploy the components individually without grouping them into an ear? Yes of course you can. Does it make any difference to have them pack together into an ear? Yes it does. It actually makes a lot of difference. One big difference is that when the war and the ejbs are deployed separately you cannot use the local interfaces. The container will treat your jsps or servlets as they are remote clients. The same when an ejb will lookup and call another ejb. An ear will solve this problem though. As you might see lot of performance gain only from simply having a different packing architecture.
If you read property files then using the FileInputStream is not the best approach. Avoid using i/o operation with j2ee application. One other option you have (which is maybe not the best but is widely used and works just fine) is to use the ClassLoader.getResourceAsStream(String name). Of course the file you need to load should be in your classpath and again you need to understand your container�s classloading architecture.
Another important thing is of course about loading common libraries. Let�s say you have a library named commons.jar and you want to make it available to your web components as well as your ejb components. For a web application it�s easy; just copy the library to the WEB-INF/lib folder within your war and it will be automatically loaded by your application at run time. With ejbs though is little bit trickier, since there is no standard place to place the common libraries (again different containers might provide different solution though). However one vendor neutral solution would be to edit the manifest files of your ejb.jar(s) and instruct them where to look for that library:


(The assumption here is that the common libraries are located within the root of your ear. Otherwise the full path is required).
Regards.
Elizabath Lima
Ranch Hand

Joined: Nov 23, 2005
Posts: 32
Hi Valentin,

Thank u so much for the reply.

But i didn't get what exactly mean by this...

> ClassLoader.getResourceAsStream(String name). Of course the file you need
> to load should be in your classpath

Probably this will be a dumbest question but ... the ClassLoader is an abstract class then is it possible to call like this ? and how can i give the properties file in classpath?

Warm regards,
Lima
Elizabath Lima
Ranch Hand

Joined: Nov 23, 2005
Posts: 32
Hi Valentin,

I think i'm clear about my previous doubt..

Thankx a lot for giving this ranch hand

Lima
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
You're very welcome Elizabath
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Packaging an EAR