CA618 Labs
Welcome to CA618 Lab 1
The aim of the first lab session is to make you familiar with the Java EJB server infrastructure. Please follow the instructions below and try to complete the whole of Lab 1.
I'd highly recommend reading Enterprise JavaBeans, 4th Edition by Bill Burke, Sacha Labourey, Richard Monson-Haefel. O'Reilly. This book is available for free through DCU's e-books service.
Some resources
The following links are some other useful resources.
EJB Server Matrix - Compare diffrent EJB containers.
TheServerSide.com - Distributed Computing Site.
JBoss - Free OSS EJB container.
Lab 1 Setup Instructions: Setting up the Blazix EJB Server on Windows XP
These instructions are based on a Sun Java tutorial, found here, but adapted so they should work in the CA labs. In the instructions below we use the Blazix EJB server, instead of the Weblogic application server used in the original Sun tutorial. A more comprehensive tutorial can be found here. You should read both at some stage.
- 1. Assumed Java 1.5 JDK is installed correctly.
- 2. Download Blazix from here.
- 3. Install blazix12.exe (just downloaded) to a writable directory (the h drive in the labs will do nicely) which will be refered to as %BLAZIX_HOME% in this document. You may set %BLAZIX_HOME% as an environmental variable or just enter the full path instead of this placeholder whenever you see it mentioned here. For example
set BLAZIX_HOME=h:\Blazix
- 4. Make up server passwords when prompted by installer.
- 5. Ensure JAVA_HOME and PATH environmental variables are set appropriately. Download and run the environmental variable settings executable from here to do this for you. You must run this script in every new dos prompt you open. If these values are not set correctly you will get an error.
- 6. Add the blazix installation directory %BLAZIX_HOME% to the PATH environmental variable or edit the command just downloaded and rerun.
- * For more information on paths and environmental variables see %BLAZIX_HOME%/docs/WinPaths.html
- 7. Read the blazix documentation located at %BLAZIX_HOME%/docs/index.html
- 8. Open a command prompt session.
- 9. Start up the blazix server from the %BLAZIX_HOME% directory by typing...
java -cp %BLAZIX_HOME%\blazix.jar desisoft.ejb.server.EjbServer
Lab 1 EJB Instructions: Building your first Stateless Session Bean
- 1. This tutorial is based on the Sun EJB tutorial located here.
- 2. Download and run the environmental variable settings executable from here.
- 3. Create a directory, lab1.
mkdir lab1 cd lab1
- 4. Save the remote interface Demo.java to the lab1 directory.
- 5. Save the home interface DemoHome.java to the lab1 directory.
- 6. Save the Enterprise JavaBean DemoBean.java to the lab1 directory.
- 7. Compile all the .java files by running the following from a command prompt session. if you get an error check that you have set the %BLAZIX_HOME% environmental variable for this dos session.
javac -cp %BLAZIX_HOME%\blazix.jar;. *.java
- 8. Create a directory, META-INF, off the lab1 directory. This directory must be spelled and located correctly.
mkdir META-INF
- 9. Save the deployment descriptor ejb-jar.xml to the META-INF directory.
- 10. Edit the deployment descriptor file and change the properties in the file to match your programs values.
- 11. Download the build batch file newbuild.cmd and place in your %BLAZIX_HOME%\lab1 directory.
- 12. Edit the build batch file and change the varaibles in the script to match your programs values i.e. Set values for PACKAGE_DIR,PACKAGE_NAME,EJB_NAME and BLAZIX_HOME (if not already set).
- 13. Run the build batch file by typing its name at the prompt. You will see an error related to the Java 1.5 JDK, ignore this as the script is written to overcome this bug.
- 14. Start up the Blazix EJB Server using the command below from the %BLAZIX_HOME% directory. Your new EJB should now be deployed if the steps were followed correctly.
java -cp %BLAZIX_HOME%\blazix.jar desisoft.ejb.server.EjbServer
- 15. Create a directory, client, off %BLAZIX_HOME%
mkdir client
- 16. Save the client DemoClient.java to the client directory.
- 17. Compile the client.
cd client javac -d . -cp %BLAZIX_HOME%\blazix.jar;%BLAZIX_HOME%\ejbdir\DemoEjb.jar;. DemoClient.java
- 18. Make sure you started the Blazix EJB server as outlined in step 14.
- 19. Run the client.
java -cp %BLAZIX_HOME%\blazix.jar;%BLAZIX_HOME%\ejbdir\DemoEjb.jar;. ejb.demo.DemoClient
- 20. Explore inside the newbuild.cmd and envset.cmd scripts to understand what each line does.
- 21. Optional: Try blazix on linux, it works more or less the same (it's only Java!) except you will need a different newbuild.cmd script called newbuild.sh written in Bash rather than DOS scripts.
- 21. Optional: Place the client and servers on different computers. The client DemoClient.java just needs the IP address of the server computer to connect and consume it's resources. So change "localhost:2050" to "serverip:portnumber".
- 22. Optional: Try your new EJB in a different EJB Server such as JBoss. You shouldn't have to change any of the code except the client.
Lab 2: Building your first Entity Bean
This week you will try to get an EJB entity bean up and running. Entity beans represent entities, or tables, in a database schema. Read up on the concept in the links at the top of the page or in the recommended text book.
- 1. Create a new directory called lab2.
- 2. Download the following files and save them to the lab2 directory. Demo2.java, Demo2Bean.java, Demo2Home.java, Demo2Client.java, ejbjar.xml, newbuild.cmd. You will probably want to put the client code in a different directory as you did for lab1.
- 3. Follow the steps from lab1 to get the various pieces compiled and running.
- 4. Read the code and alter it so you understand what is going on.
- 5. How does the code in lab2 differ from lab1?
- 6. Re-implement the code so the bean connects to an MS Access or MySQL database.
- 7. Todo the database parts you must create a MS Access Database. Create a database with one table, containing at least 2 columns.
- 8. Create an ODBC datasource for your new database. To do this on the lab computers run the following, and configure a System DSN using the MS Access Driver. I assume you have called your DSN, lab2DSN.
c:\windows\system32\odbcad32.exe
- 9. Open the ejb.ini in %BLAZIX_HOME% and add the following lines..
dataSource.name:lab2DataSource dataSource.lab2DataSource.odbc:lab2DSN ejb.Demo2.dataSource:lab2DataSource ejb.Demo2.table:Demo2
- 10. Open Demo2Bean.java and change the bean context to public from private transient.
- 11. Read the O'Reilly book on Container Managed Persistence to see what changes you must make to your ejb-jar.xml file and to the code itself.
- *Note some of the files you download may have a number appended to them. Remove this number when saving locally. The number is used to avoid version conflicts on my webserver.
Lab 3:
This week we will implement an EJB-based component architecture with a session bean that uses an entity bean: read about these architectures in the literature. Try to get the following skeleton code (in addition to the Demo2 files from lab2) up an running
- 1. Create a new directory called lab4.
- 2. Download the following files and save them to the lab4 directory. Demo4.java, Demo4Bean.java, Demo4Home.java, Demo4Client.java, ejbjar.xml, newbuild.cmd. You will probably want to put the client code in a different directory as you did for lab1.
- 3. Follow the steps from lab1 to get the various pieces compiled and running.
- 4. You need to start the Ejb server with a reference to any internally referenced EJBs. To start the server do the following (if Demo2 is the Entity bean that this session bean is going to use) ...
H:\Blazix>java -cp %BLAZIX_HOME%\blazix.jar;%BLAZIX_HOME%\ejbdir\Demo2Ejb.jar desisoft.ejb.server.EjbServer
- 5. Read the code and alter it so you understand what is going on.
- 6. How does the code in lab4 differ from lab1 and lab2?
- *Note some of the files you download may have a number appended to them. Remove this number when saving locally. The number is used to avoid version conflicts on my webserver.
Lab 4:
Using all the knowledge you have gained from the labs so far, build a basic reservation system that uses at least 2 session beans and 2 entity beans. The entity beans should represent database tables in an MS Access or MySQL Database. The scope and functionality are up to you.


