Developing Session EJBs with Borland JBuilder Enterprise
In the current Web application development world, to keep up with the cornucopia of the Web technologies, developers need to keep up with the tools. Some newer technologies, such as, AJAX don't yet have a widely accepted IDEs, even though some promising tools are starting to appear. The more seasoned technologies, such as J2EE or .NET, have many mature tools on the market. J2EE, in particular, has been around for a while and many of the Java development environments are sophisticated enough to offer a substantial reduction in the development/debugging time and simplify software life cycle management. The modern tools usually feature visual designers, code completion and auto generation, in-memory and remote debugging and other features.
In this article, I will discuss the creation and use of an Enterprise Java Beans that are J2EE server components and put their role in the perspective with the whole J2EE application. The sample project will be done with the Borland JBuilder 2006 and I will use BEA WebLogic 9 as an application server. I will rely mostly on the excellent visual designers provided by JBuilder to create enterprise modules, such as WAR, EAR, and EJB, but I will note what is available with other tools, such as Eclipse. I will assume that you are comfortable with the Java language and know the basic concepts of J2EE application packaging and structure.
J2EE IDEs Background
Presently, the dominant player in the Java IDE marketplace is the free Eclipse IDE. It is a first-rate development IDE and a plug-in platform with its own SDK, and it has obtained the largest market share* extremely quickly since its release. I have described it briefly in "Modern Java Frameworks for Web Development." However, in the form in which it is currently available, Eclipse does not contain many of the integration and design components, such as UML modeling, App server integration, visual designers, Swing editing, and so forth that other Java IDEs provide. Many such components exist, but need to be installed as a plug-in. However, some of them may not work peacefully with others, and there is always a research and integration time involved, as well as learning how to use the plug-in itself.
* Counting the usage of Eclipse IDE itself and all other IDEs that are based on it.
Many of the commercial IDEs, such as IBM WebSphere Studio (currently renamed "WebSphere Developer for zSeries"), NitroX, or Exadel Studio use Eclipse framework at their core. They add many custom plug-ins targeting different aspects of J2EE application development that are designed to work together. On the other hand, Borland's JBuilder IDE is using a custom framework, but its future versions also will be based on Eclipse. Presently, JBuilder is a well-designed tool that offers everything needed for Java development in one package. All of JBuilder's modules are tightly integrated and offer a rewarding design and development experience with substantially less coding. This is mostly attributed to its visual designers and well thought-out interface. All of the features are beyond the scope of this article, but I will talk about the visual EJB designer, GUI WAR and EAR structure editors, and JBuilder's integration with the application servers to run and debug Web apps.
Setup and Environment
For the purposes of this article, I am using BEA WebLogic's EJB and servlet containers, but JBuilder can easily integrate with other application servers out of the box, such as, Tomcat, JBoss, and so on. After installing WebLogic (and configuring a domain and a server), you need to enable it and point to its location under Enterprise Menu -> Configure Servers Window.
After that, JBuilder will ask whether you will want to use this server to deploy and run your applications during the configuration steps of the WAR and EAR modules. The setting that tells JBuilder which server to use is stored per project and can be changed at any time from the project's Properties -> Server option.
Additionally, JBuilder will correctly create/modify xml deployment descriptors for the Web application to match the target application server. The XML descriptor also can be changed later on, either by hand or using GUI editor. JBuilder provides start/stop and debug run options for the target server, called "runtime configuration," and even an internal browser to run and test the application.
The purpose of the sample project will be to get weather information from a Stateless Session Bean; it will have a getWeatherData method that takes a zip code. The method returns a static string, but in a real application it can go out to RDBMS, read from a Web service, XML stream, or any other data feed.
Here is the general structure of the project:
To invoke interaction to the Bean (which I'll discuss shortly), the application needs to process user requests and a form to accept input. The first will be accomplished with the Java Servlet and the second will be done via a simple HTML page. I will not actually code either of them, but create them with the JBuilder. In a real enterprise application, the input could be a JSP page or any other front end technology.
According to the J2EE specification, the Servlet and all the HTML resources will be packaged in a Web module (WAR file), the bean will be placed in a separate jar, and both of them will be included in an EAR archive and deployed to the server. Again, JBuilder will do most of the work for me, including the packaging and deployment steps.
Before creating the servlet, I have created a project with the name EJB_WL and added a package with the same name ejb_wl,, which will hold my Servlet and the Bean. On the file system, both will be located under the src folder in the project directory (see the Appendix).