Now we have all of our files in the correct directories. The next step is to
compile the source code into class files.
A D V E R T I S E M E N T
The following commands should be
executed from the top of the directory structure created earlier (c:\ejb_example
on my computer).
Also, you'll need to ensure your javac command is working and
that you have the proper development kits installed. (These commands are for
Microsoft Windows. If running this example on another operating system, just
edit these commands as required.) The LIBDIR variable should point to the
directory that contains jboss-j2ee.jar.
(The line breaks are for formatting only. Execute these on one line.)
Remember that EJBs execute in an EJB container on the server. In our case
this will be the jboss application server. We need to package the server code
into a jar file named helloserver.jar. This jar will be copied into the proper
jboss deployment directory in the next step. Likewise, we need to package the
client code, the code that will call and use the EJB, into a jar file named
helloclient.jar. The client code can be run from any computer on the network,
but in our case we'll just run jboss in one DOS window and the client in another
DOS window on the same computer.
Execute the following command from your c:\ejb_example\target\client
directory. (Don't forget the trailing "." at the end.)
jar cvf ..\..\assemble\helloclient.jar .
Execute the next command from your c:\ejb_example\target\server directory.
(Again, there is a trailing ".".)
jar cvf ..\..\assemble\helloserver.jar .
After executing these jar commands you should have a helloclient.jar and a helloserver.jar in the assemble directory.
Deploy to jboss
Create a JBOSS_HOME environment variable and set it to the
jboss installation directory (for instance, c:\jboss-3.2.5).
Create a LIBDIR environment variable and set it to the
client directory under JBOSS_HOME (for instance, %JBOSS_HOME%\client).
Place the helloserver.jar in the %JBOSS_HOME%\server\default\deploy
directory.
From the command prompt:
%JBOSS_HOME%\bin\run.bat
When jboss starts up, you should see logging statements indicating that the Hello EJB has been deployed. Here is what I have in my command window:
08:56:07,656 INFO [EjbModule] Deploying Hello
08:56:08,424 INFO [EJBDeployer] Deployed: file:c:\jboss-4.0.1sp1\server\default\deploy\helloserver.jar
Run The Client
To run the client, open a new DOS window (you should have jboss already running in a separate window).
Create a JBOSS_HOME environment variable and set it to the
jboss installation directory (for instance, c:\jboss-3.2.5)
Create a LIBDIR environment variable and set it to the
client directory under JBOSS_HOME (for instance, %JBOSS_HOME%\client)
Change directory to the assemble directory that contains
helloclient.jar
In your client DOS window, you should see "Hello! World" print out. In the server DOS window, you should see "Someone called sayHello()" print out. The client just executed our sayHello business method from within the jboss application server.