
Deploying to WebSphere 5.1 on Windows/Linux
This demo shows how JReport Engine Bean can be deployed as an EJB to WebSphere 5.1 for both windows 2000 professional and Linux. The steps below are based on Windows. The procedure for Linux is similar, where you only need to change the path information.
In this demo, an EJB client is HttpServerlet which calls EJB module deployed in the same WebSphere 5.1. In the EJB module, the session bean calls JReport Engine Bean to run and export a report to the HTML format. The below image illustrates the working structure of this demo.

JReport Engine Bean is the module running report templates against a data source and exporting report results to the specified format such as HTML, PDF, RTF and so on (see Exporting report results to different file formats for methods about exporting report result to other formats).
The steps for this demo are as below:
- Preparation
- Developing the EJB session bean and the servlet that calls the EJB
- Deploying the EAR file and starting the servlet
Preparation
To prepare for this demo, you will need to install the following:
- Install WebSphere 5.1 to
C:\websphere5.1.
- Install WebSphere Studio Application Developer 5.1 (abbreviated as WSAD) to
C:\IBM. In this demo, we will use WSAD to:
- develop EJB session beans
- develop EJB client servlet
- generate deployment descriptors
- generate the ear file for the later deployment
- Install JReport Designer to
C:\JReport\Designer. You will then have the following JReport Engine Bean and related libraries in C:\JReport\Designer\lib:
- JREngine.jar - It is required.
- log4j-1.2.8.jar - Required. It is called by JReport Engine to generate log information at runtime.
- sac.jar - Required. It is used to parse xml files.
- hsqldb.jar - It is necessary for this demo. This demo runs a report against HSQL database, and hsqldb.jar is the hsqldb driver.
This demo will export the report result to the HTML format. If you want to export the report result to other formats, add the corresponding class files or jars. They are:
- Mail: mail.jar and activation.jar
- Excel: poiHSSF_151.jar
- XML: xml-apis.jar and xercesImpl.jar
- PDF: Itext.zip
Note: JReport Engine Bean in JReport Designer is of single thread. That is, you can only have it run one report at a time. To build your production EJB which calls JReport Engine Bean for concurrent multiple reports, contact Jinfonet Support about the JReport Server Engine product.
Developing the EJB session bean and the servlet that calls the EJB
In WSAD, first create a project that contains the framework of the EJB and the servlet which calls the EJB. Then, go to their editors to modify the code for the EJB and servlet. Follow the steps below:
- Start WebSphere Studio 5.1. Create a new Java EE project named JReportEJBDemo.
To create the new project JReportEJBDemo,
- Select Project from the File menu. The New Project dialog will then appear.
- Highlight Java EE on the left panel in the New Project dialog, and then choose Enterprise Application Project from the right panel. Click the Next button in this dialog. You will then be taken to the New Enterprise Application Project dialog. Then, click Next in this dialog directly.
- Type JReportEJBDemo into the Project name text box, and click Next.
- Click New Module and on the New Module Project dialog, select EJB Project and Web Project. Then, click the Finish button.
- You will now see that JReportEJBDemoEJB and JReportEJBDemoWeb have been generated. Click Finish.
- Add source files for the EAR.
- Right-click Utility JARs in JReportEJBDemo, and click Import from the shortcut menu. The Import dialog appears. Select File System from the Select an import source panel, and then click the Next button.
- Click the Browse button and select the directory
C:\JReport\Designer\lib. Select the files JREngine.jar, log4j-1.2.8.jar, sac.jar and hsqldb.jar. For the Into folder text box, click the Browse button and select JReportEJBDemo. Then, click Finish in the Import dialog.
- Create an EJB session bean named JReport for JReportEJBDemoEJB.
- From the Java EE Hierarchy tree, expand EJB Modules, right-click Session Beans in JReportEJBDemoEJB, and on the shortcut menu, click Session Bean from the sub-menu of New.
- In the New Enterprise Bean dialog, click Next.
- This dialog helps you "Create a 2.0 Enterprise Bean". Type JReport in the Bean name text box. Type demo in the Default Package text box. Click Next to go to the next dialog which shows the Enterprise Bean Details (perform no actions in this dialog except for clicking Next). Then, click Finish.
- Now, in the Java EE Hierarchy tree, three EJB classes have been generated in the Session Beans node. They will automatically have been named JReportHome, JReport, and JReportBean. Note that JReportHome is the EJB home class, JReport is the EJB object class and JReportBean is the EJB bean class.
- Edit the three EJB classes.
- JReportHome: Insert a method which is used to create the EJB object.
- JReport: Insert methods which have been defined to call JReport Engine Bean.
- JReportBean: Implement the methods in the JReport class (the EJB object class).
- Check the JNDI name.
Double-click the session bean JReport. In the right panel, find out the JNDI Name, which will be used in the servlet lookup later.
- Put external classes/jars to the WSAD compiler.
- Right-click JReportEJBDemoEJB, and choose Properties from the shortcut menu.
- Select Java Build Path on the left panel.
- In the Libraries tab. Then, click the Add External JARs button to add JREngine.jar (go to
C:\JReport\Designer\lib, rename the file JREngine.jar to JREngine.jar).
- In the Order and Export tab, check JREngine.jar, and move it to the top. Then, click OK.
- Add JREngine.jar, log4j-1.2.8.jar, and hsqldb.jar to the class path which is used to run the EJB.
- On the Window menu, click Other from the sub-menu of Open Perspective.
- Select Plug-in Development in the Select Perspective dialog.
- In the Package Explorer, expand JREportEJBDemoEJB in META-INF of ejbModule. Then, double-click MANIFEST.MF to open it.
- In the Dependencies panel of the JAR Dependency Editor, select all the jar files in the JAR or Module column.
- Use WSAD to build the container classes and deployment descriptors for the EJB.
- Right-click JReportEJBDemoEJB in EJB Modules, and click Deployment and RMIC Code from the Generate sub-menu. Check JReport.
- Click Finish in the Generate Deployment and RMIC Code dialog and the changes will be saved at the same time.
- Export this JReportEJBDemoEJB to a jar.
- Right-click JReportEJBDemoEJB and select Export EJB JAR File from the Export sub-menu.
- In the Export dialog, specify a directory in the Destination text box. Use the default name JReportEJBDemoEJB. The JReportEJBDemoEJB.jar will be generated in the specified path.
- The EJB, which is JReportEJBDemoEJB, is now ready. Next, you should finish the servlet code in the created web module, that is JReportEJBDemoWeb, to call this EJB via RMI. To generate the servlet code,
- Double-click JReportEJBDemoWeb. In the Web Deployment Descriptor, click Details of Servlets and JSPs panel.
- Click New to bring out the New Servlet dialog. Type JRServer in the Class name text box, and click Finish. The JRServer.java is generated.
- Add the following code into the JRServer.java.
InitialContext ic = new InitialContext();
Object objRef = ic.lookup("java:comp/env/jreport");
JReportHome home =(JReportHome)PortableRemoteObject.narrow(objRef,
JReportHome.class);
this.jreport = home.create();
|
Note: The above code Object objRef = ic.lookup("java:comp/env/jreport") calls AliasName – jreport. Therefore, we will create an alias name for the EJB in the web module.
- Double-click JReportEJBDemoWeb in the References panel. Then click Details.
- In the EJB References panel, click Add, and rename New EJB Ref to jreport.
- In the Details panel, click Browse to the right of the Lin text box. Then, select JReportEJBDemoEJB in the Location panel in the EJB Selection dialog, and click OK.
- In the WebSphere Bindings panel, check the JNDI Name, to make sure that it is the same as the name mentioned in step four.
- Double-click JReportEJBDemoWeb in the Pages panel, and click Details. In the Login panel, select Basic from the Authentication method drop-down list. Type index.jsp in the Realm name text box.
- Create index.jsp.
- Switch to Plug-in Development Perspective, in the Package Explorer, in JReportEJBDemoWeb, right-click WebContent, and select File from the New sub-menu.
- In the New File dialog, type index.jsp in the File name text box, and then click Finish.
- Write your JSP page code into the index.jsp file.
- Now, both the EJB and the servlet are ready in the same application. The next step is to export an EAR file which includes the EJB and web project.
- In the Java EE Hierarchy tree, select JReportEJBDemo, right-click it and click Export EAR File.
- In the Export dialog, specify a directory in the Destination text box, using the default name JReportEJBDemo. JReportEJBDemo.ear will be generated in the specified directory.
Deploying the EAR file and starting the servlet
To deploy the EAR file:
- Open the WebSphere Administration page.
- Select Install New Application in Applications in the left panel of the page.
- For the Preparing for the application installation section, click the Browse button of the Local path. Then, go to the directory where JReportEJBDemo.ear exists, and select it.
- Click Next for all the following steps until finish, and save the task.
To start the servlet:
- Select Enterprise Application in Applications in the left panel of the administration page.
- In the Enterprise Application panel, select JReportEJBDemo and then click the Start button.
- Use a web browser to load the JSP page. For example, the URL may be like this:
http://192.168.129.53:9080/JRServer/index.jsp.
Note: When deploying JReport Engine Bean as an EJB to WebSphere5.1, JReport Engine Bean is wrapped into a session bean. For more information, refer to the demo program in ejbWebsphere51.zip in C:\JReport\Designer\help\designer\samples.
