| |
1.准备文件 需要的软件:jdk1.3(for win) ,j2ee_1_2_1_sdk,jboss2.0(www.jboss.org) 需要的文档:j2ee_1_2_1_sdk_doc,devguide1_2_1 2.准备环境 安装jdk1.3(支持jboss),装完后检查一下环境变量,可以编译运行一个小程序试一下. 安装jboss2.0,完成后运行bin/run.bat试一下.jndi 端口是1099,web端口是8080,可以用浏览器试一下,1099端口会返回一段乱码,8080端口返回空. 3.编译和打包 按照javatm 2 enterprise edition developer´s guide (v1.2.1)的getting started章中说的编译例子程序 converterejb,然后用deploy tool打包生成 converterapp.ear. 用jar -xvf converterapp.ear 从中抽取 ejb-jar-ic.jar 这是打包好的和bean有关的三个文件和工具生成meta-info/*.xml文件(所谓的deployment descriptor). 然后运行jboss的deploy tool打开ejb-jar-ic.jar,设置jndi name为myconverter.然后保存.(该工具会自动生成jboss的deployment descriptor) 在把ejb-jar-ic.jar拷到jboss/deploy目录下,jboss会自动发布该bean.. 4.运行客户端程序测试 按照jboss的教学文档,修改 converterclient.java为 import javax.naming.*; import java.util.hashtable; import javax.rmi.portableremoteobject; import java.util.properties; import java.io.fileinputstream; import javax.rmi.portableremoteobject; import converter; import converterhome; public class converterclient { public static void main(string[] args) { try { properties props = new properties(); properties sysprops = system.getproperties(); try { props.load (new fileinputstream ("test.properties")); sysprops.putall(props); } catch (exception e) { system.err.println ("can´t read `test.proprties´"); system.exit (-1); } system.setproperties (sysprops); context initial = new initialcontext(); object objref = initial.lookup("myconverter"); converterhome home = (converterhome)portableremoteobject.narrow(objref, converterhome.class); converter currencyconverter = home.create(); double amount = currencyconverter.dollartoyen(200.00); system.out.println(string.valueof(amount)); amount = currencyconverter.yentoeuro(200.00); system.out.println(string.valueof(amount)); } catch (exception ex) { system.err.println("caught an unexpected exception!"); ex.printstacktrace(); } } } test.properties文件内容如下 java.naming.factory.initial=org.jnp.interfaces.namingcontextfactory java.naming.provider.url=xxx.xxx.xxx.xxx:1099 (写上jboss所在机器的ip) 然后运行compileclient.bat和testclient.bat,就可以享受成功的喜悦了.
|
|