Developing Session EJBs with Borland JBuilder Enterprise, Page 4
EAR: Enterprise Application Archive Module
To combine all of the parts of a J2EE application that I have created into the final application, I created an Application Module, a logical entity corresponding to the EAR archive. When the application is built, the JBuilder will jar all of the components and place the final EAR archive file in the project folder. The file then can be deployed to the application server for execution, via JBuilder or a server-provided utility.
The application module wizard is located in the Enterprise object gallery. Notice that in JBuilder, if Web Module and EJB module already exist in the project, including them in the EAR is a matter of selecting a check box next to their names on the wizard.
If the EAR module is created first, the other components can be added later on through Application Module properties. But, I find it easier to add the EAR module last and simply include the already existing parts in it.
Here is the final view of the build project structure. JBuilder compiled EJB stubs for the Weather Bean and created all files automatically. They are under the package of the project.
The logical Application, Web, and EJB entities show three things:
- The final compiled and packaged file
- A logical grouping of J2EE deployment descriptors corresponding to the application server associated with the project
- A view to the file system for that module
The only thing that remains is to deploy ApplicationModule.ear.
Note: You don't always need to create a application module. Some projects that don't use EJB or other Server components can be deployed with just a WAR file or Web Module.
The application.xml deployment descriptor tells the app-server which modules are included in the EAR.
<application> <display-name>ApplicationModule</display-name> <module> <ejb>EJBModule.jar</ejb> </module> <module> <web> <web-uri>WebModule.war</web-uri> <context-root>WebModule</context-root> </web> </module> </application>
The entire project creation and configuration was done fairy quickly, mainly due to the visual designers and editors. The JBuilder's visual project representation also follows the J2EE structure closely. To do the same project with other tools, such as Eclipse, you will need additional plug-ins. Usually, plug-ins for a particular app-server from one vendor will integrate together, but their sophistication will depend on the vendor. However, if you decide to switch your app-server from Tomcat to JBoss, you will need to search for and install new ones.
Running the Application
After deployment, I ran the application from the runtime configurations menu. This has automatically started the server and invoked the HTML form. The form automatically loaded in the JBuilder's internal browser, but at this point the URL can be loaded in any browser. Here is the screen shot of the running application and what it returns when the form is submitted.
To recap, the string object "zip code" was posted to the servlet, which in turn located one of the session EJBs from the pool maintained by the WebLogic server. The bean was located by its public interface. The servlet then invoked the getWeatherMethod() method on the bean, passed the zip code parameter, and retuned its response to the client.
In this article, I have covered the basics of a complete J2EE project with all the main components, such as a Web module containing Servlet and WAR deployment descriptors and other resources, an EJB module containing a Session Stateless Bean, an Application Module containing application deployment descriptors, and both the WAR and the EJB archives. The main emphasis was on EJBs and visual designers built into the JBuilder IDE. The whole project did not require a lot of writing. The visual designers eliminated the tediousness of the template code associated with the Servlet and the EJB, and tremendously reduced coding time. The modern development tools offer a lot of flexibility when it comes to enterprise Web development, and they are certainly mature enough to eliminate low-level plumbing, allowing developers to concentrate on the overall architecture of the project.
File System View of the project:
- Sun EJB Specification: http://java.sun.com/products/ejb/docs.html
- Borland Software Corporation: http://info.borland.com/techpubs/jbuilder/
- Wikipedia: http://en.wikipedia.org/wiki
About the Author
Vlad Kofman is a Senior System Architect. He has implemented enterprise-scale projects for the major Wall Street firms, defense contracts, and the U.S. government. His main interests are object-oriented programming methodologies and design patterns.
Page 4 of 4