Tuesday, October 31, 2006

How to package an application into a ear file

This is for those who want to know the ideal and most common way an application is packaged in the form of an ear file. Here's how the application structure will look like:

myApp.ear
|
|--------- META-INF
| |
| |---------- application.xml
|
|--------- myEJB.jar
| |
| |--------- META-INF
| | |
| | |-------- ejb-jar.xml
| |
| |------ org
| | |----- myApp
| | |------- ejb
| |-------- *.class
|
|---------- myWeb.war
| |
| |----- WEB-INF
| |------ web.xml
| |
| |------ jsp
| |---- *.jsp
|
|---------- commonUtil.jar
|
|--------- org
|----- myApp
|------ common
|----- *.class


The application.xml present in the META-INF folder of the ear will contain the following:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" "http://java.sun.com/dtd/application_1_3.dtd">
<application>
<display-name>helloworld</display-name>

<module>
<java>commonUtil.jar</java>
</module>

<module>
<web>
<web-uri>myWeb.war</web-uri>
<context-root>/myWeb</context-root>
</web>
</module>

<module>
<ejb>myEJB.jar</ejb>
</module>

</application>