In Calling EJB 3 from JRuby client, I wrote how to call EJB3 deployed to glassfish from a JRuby script. This post will show how to do it with JBoss EJB3, reusing the same EJB3 as the previous post (A simple EJB 3 on JBoss application server). Steps 1-7 (creating EJB3 classes, starting JBoss server, deploying EJB, preparing
The JRuby script (testEJB.rb) is almost identical to the one for glassfish, except the default jndi name. TODO: pass it in as parameter instead of hardcoding it.
jndi.properties
and log4j.properties
) are exactly the same as that post. Here I will show the client script code and how to run it.The JRuby script (testEJB.rb) is almost identical to the one for glassfish, except the default jndi name. TODO: pass it in as parameter instead of hardcoding it.
require 'java'Before running the script, we need to set the environment variable CLASSPATH, which is of course different from the one for glassfish.
include_class 'javax.naming.InitialContext'
ic = InitialContext.new
foo = ic.lookup("FooBean/remote")
result = foo.echo("This is foo!")
puts "Calling the EJB 3 : #{foo} returned #{result}"
set CLASSPATH=%JBOSS_HOME%\lib\*;%JBOSS_HOME%\client\*;%JBOSS_HOME%\server\default\lib\*;C:\simple-ejb3\classesThe above classpath value works only with JDK 6 or later. If you are stuck with JDK 5, then:
jruby testEJB.rb
set CLASSPATH=%JBOSS_HOME%\lib\jboss-aop-jdk50.jar;Technorati Tags: JBoss, EJB3, JRuby
%JBOSS_HOME%\client\jbossall-client.jar;
%JBOSS_HOME%\server\default\lib\jbosssx.jar;
C:\simple-ejb3\classes