CORBA入门

来源:互联网 发布:天威网络客服电话 编辑:程序博客网 时间:2024/05/16 15:09
<转自 http://blog.csdn.net/james05y/archive/2007/05/14/1607958.aspx>

一、使用到的软件
JacORB 2.3
Eclipse SDK 3.3
JDK5 1.5.0_11
ORB Studio 7.7.7

使用的系统为Windows XP SP2。版本号可能不一定要完全按照上面,但是如果你配置成功不了,不妨就按上面来弄。

二、为eclipse安装corba开发插件。
ORB Studio是开发corba的插件,用于eclipse。

安装其实很简单,把ORBStudio_7.7.7.jar文件拷贝到eclipse的plugins目录。

三、安装JacORB,生成jaco.bat

(1)安装
解压JacORB-2.3.0-bin.zip到D:\JavaTools,JacORB的根目录为JacORB-2.3.0。

(2)生成jaco.bat,这个脚本用来启动服务端和客户端程序。
进入D:\JavaTools\JacORB-2.3.0,执行下列的命令

set ANT_HOME=E:\apache-ant-1.7.0
set CLASSPATH=%ANT_HOME%\lib\ant.jar;
set PATH=%PATH%;%ANT_HOME%\bin;
ant jaco



就可以生成jaco.bat,自己编写一个也可以,只要改掉里面的路径。
######################################################
@echo off
rem call java interpreter
java -Djava.endorsed.dirs=D:\JavaTools\JacORB-2.3.0/lib -Djacorb.home=D:\JavaTools\JacORB-2.3.0 -Dorg.omg.CORBA.ORBClass=org.jacorb.orb.ORB -

Dorg.omg.CORBA.ORBSingletonClass=org.jacorb.orb.ORBSingleton -classpath %CLASSPATH% %*
######################################################

四、在eclipse里面配置ORB Studio和JacORB。
在eclipse的菜单栏中,选【windows】->[preferences]->[ORB Studio]->[IDL Compiler],选中JacORB。
然后展开[IDL Compiler],设置JacORB的IDL Command和Command Options。

默认参数是:
IDL Command:java
Command Options:-cp "/Tools/JacORB/lib/idl.jar;/Tools/JacORB/lib/logkit-1.2.jar" org.jacorb.idl.parser -d %D% %F%

第二个参数要设置成正确的路径。
-cp "D:\JavaTools\JacORB-2.3.0\lib/idl.jar;D:\JavaTools\JacORB-2.3.0\lib/logkit-1.2.jar" org.jacorb.idl.parser -d %D% %F%


五、corba程序示例
在D:\JavaTools\JacORB-2.3.0\demo取一个简单的例子hello
以下操作在eclipse中进行。
1、建立一个IDL文件,如demo.idl
module demo
{
    module hello {
        interface GoodDay {
            string hello_latin1();
            wstring hello_chinese();           
        };
    };
};

2、右键点击demo.idl文件,选[ORB Menu]->[Compile],会生成demo.hello包,里面包含7个自动生成的文件
_GoodDayStub.java
GoodDay.java
GoodDayHelper.java
GoodDayHolder.java
GoodDayOperations.java
GoodDayPOA.java
GoodDayPOATie.java

3、实现demo.idl文件hello模块中GoodDay接口,手动创建GoodDayImpl.java文件
package demo.hello;

public class GoodDayImpl extends GoodDayPOA {

 public String hello_chinese() {
  // TODO Auto-generated method stub
  return "你好, 世界";
 }

 public String hello_latin1() {
  // TODO Auto-generated method stub
  return "Hello, World";
 }
}

4、创建Server和Client(服务器端和客户端)程序
Server.java
//////////////////////////////////////////////////////////////////////
package demo.hello;

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;

public class Server {
 public static void main(String[] args) {
  try {
   ORB orb = ORB.init(args, null); // 初始化 ORB
   
   POA poa = POAHelper.narrow(orb
     .resolve_initial_references("RootPOA")); // 初始化 POA

   poa.the_POAManager().activate();

   // 创建一个 GoodDay 对象
   GoodDayImpl goodDayImpl = new GoodDayImpl();

   // 创建 GoodDay 对象的引用
   org.omg.CORBA.Object obj = poa.servant_to_reference(goodDayImpl);

   // 使用 naming service
   NamingContextExt nc = NamingContextExtHelper.narrow(orb
     .resolve_initial_references("NameService"));
  
   nc.bind(nc.to_name("hello.goodDay"), obj); // 绑定对象

   orb.run();
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}

Client.java
//////////////////////////////////////////////////////////////////////
package demo.hello;

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;

public class Client {
 public static void main(String[] args) {
  try{
   GoodDay goodDay;
  
   ORB orb = ORB.init(args, null); // 初始化 ORB
  
   // 使用 naming service
   NamingContextExt nc = NamingContextExtHelper.narrow(orb
     .resolve_initial_references("NameService"));
   org.omg.CORBA.Object obj = nc.resolve(nc.to_name("hello.goodDay")); //解析对象
  
   goodDay = GoodDayHelper.narrow(obj); //转换
  
   // GoodDay 接口调用
   System.out.println(goodDay.hello_latin1());
   System.out.println(goodDay.hello_chinese());
  }catch(Exception e) {
   e.printStackTrace();
  }
 }
}

5、运行程序
(1)运行JacORB的ns
先把jacorb_properties.template文件另存为jacorb.properties,且把下面两行
#ORBInitRef.NameService=file:/c:/NS_Ref
ORBInitRef.NameService=http://www.x.y.z/~user/NS_Ref
改为
ORBInitRef.NameService=file:/c:/NS_Ref
#ORBInitRef.NameService=http://www.x.y.z/~user/NS_Ref

注意:
ORBInitRef.NameService=file:/d:/NS_Ref
设成D盘或E盘死活不行。

先设置环境变量
======================================================
set JacORB_HOME=E:\JacORB_2.3.0_beta2
set CLASSPATH=.;%JacORB_HOME%\lib\idl.jar;%JacORB_HOME%\lib\jacorb.jar;%JacORB_HOME%\lib\logkit-1.2.jar;
set PATH=%PATH%;%JacORB_HOME%\bin;
======================================================

ns

(2)运行Server和Client
进入代码目录demo的上级目录(例如:cd E:\workspace\CorbaTest\bin),在运行之前设置环境变量,然后运行下面的代码

jaco demo.hello.Server

jaco demo.hello.Client

启动NS

E:\JacORB_2.3.0_beta2>ns
[jacorb.orb.print_ver] INFO :
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        JacORB V 2.3-beta-2, www.jacorb.org
        (C) The JacORB project 14-Oct-2006
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[jacorb.orb] INFO : Property "jacorb.hashtable_class" is set to: java.util.Hasht
able
[org.jacorb.orb.codes] WARN : Warning - unknown codeset (GBK) - defaulting to IS
O-8859-1
[jacorb.orb.intercept] INFO : InterceptorManager started with 0 Server Intercept
ors, 0 Client Interceptors and 1 IOR Interceptors
[jacorb.orb.singleton] INFO : created ORBSingleton
[jacorb.naming] INFO : NS up
[jacorb.orb] INFO : ORB run


启动Server:

E:\workspace\CorbaTest\bin>jaco demo.hello.Server
[jacorb.orb.print_ver] INFO :
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        JacORB V 2.3-beta-2, www.jacorb.org
        (C) The JacORB project 14-Oct-2006
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[jacorb.orb] INFO : Property "jacorb.hashtable_class" is set to: java.util.Hash
able
[org.jacorb.orb.codes] WARN : Warning - unknown codeset (GBK) - defaulting to I
O-8859-1
[jacorb.orb.intercept] INFO : InterceptorManager started with 0 Server Intercep
ors, 0 Client Interceptors and 1 IOR Interceptors
[jacorb.poa] INFO : oid:
00 15 2B 05 4C 21 35 24 02 1F 30 ..+.L!5$..0
object is activated
[jacorb.poa] INFO : Using server ID (1842945734) for transient POA
[jacorb.orb.singleton] INFO : created ORBSingleton
[jacorb.orb.giop] INFO : ClientConnectionManager: created new ClientGIOPConnect
on to 10.0.18.30:4008 (c68c3)
[jacorb.orb.iiop] INFO : Connected to 10.0.18.30:4008 from local port 4026
[jacorb.orb] INFO : ORB run


启动Client:

E:\workspace\CorbaTest\bin>jaco demo.hello.Client
[jacorb.orb.print_ver] INFO :
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        JacORB V 2.3-beta-2, www.jacorb.org
        (C) The JacORB project 14-Oct-2006
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[jacorb.orb] INFO : Property "jacorb.hashtable_class" is set to: java.util.Hash
able
[org.jacorb.orb.codes] WARN : Warning - unknown codeset (GBK) - defaulting to I
O-8859-1
[jacorb.orb.intercept] INFO : InterceptorManager started with 0 Server Intercep
ors, 0 Client Interceptors and 1 IOR Interceptors
[jacorb.orb.singleton] INFO : created ORBSingleton
[jacorb.orb.giop] INFO : ClientConnectionManager: created new ClientGIOPConnect
on to 10.0.18.30:4008 (872380)
[jacorb.orb.iiop] INFO : Connected to 10.0.18.30:4008 from local port 4041
[jacorb.orb.giop] INFO : ClientConnectionManager: created new ClientGIOPConnect
on to 10.0.18.30:4025 (f11404)
[jacorb.orb.iiop] INFO : Connected to 10.0.18.30:4025 from local port 4042
hello
你好 !


阅读(2064) | 评论(4) | 转发(0) |
0

上一篇:为什么Java的foreach比for慢??

下一篇:Spring自动代理

相关热门文章
  • linux好文章mark链接备忘录...
  • 讨论面向对象编程中的多态性的...
  • 常见服务器类型及其区别...
  • nginx教程从入门到精通(ttlsa...
  • 开源自动化配置管理工具Puppet...
  • JDK1.6官方下载_JDK6官方下载_...
  • MyEclipse6.5下载及注册码...
  • Eclipse 插件安装、升级和卸载...
  • Eclipse+MyEclipse的配置
  • 最新版SWT Designer 6.0 安装,...
  • 如何学习linux内核
  • Linux分区扩容问题
  • linux系统机器,锁屏后,重新...
  • oracle vm 宕机不能自动漂移,...
  • 如何读取一个持续输出内容程序...
给主人留下些什么吧!~~

chinaunix网友2008-11-03 15:41:34

我用的vc,运行时出错:omniORB:ORB_init failed: Bad parameter for ORB configuration option nativeCharCodeSet,reason: Unknowe code set name

回复 | 举报

chinaunix网友2008-04-23 09:13:33

没注意你的问题:1.jacorb_properties.template jacorb.properties这两个文件目录下都有,覆盖就可以,也可以自己修改,就是些环境变量设置2.JacORB_2.3.0_beta2 JacORB安装目录,就是解压目录3.e:\workspace\CorbaTest\bin eclipse java工程生成类目录,eclipse里可以设置

回复 | 举报

小小百合2008-04-07 14:47:11

我在第5步运行程序开始开始出错.(前面都通过)提示jaco不是内部或外部命令有几个疑问第一,先把jacorb_properties.template文件另存为jacorb.propertiesjacorb.properties这个文件和jacorb_properties.template放在同一目录下吗(home/etc/下)第二,设置环境变量set JacORB_HOME=E:\JacORB_2.3.0_beta2这个E:\JacORB_2.3.0_beta2是什么路径看开始,不是把JacORB放在d:\JavaTools下了吗第三,进入代码目录demo的上级目录(例如:cd E:\workspace\CorbaTest\bin),请问e:\workspace\CorbaTest\bin是eclipse的工作目录(workspace)下的CorbaTest工程吗如果是,CorbaTest是什么类型项目?我的为什么没有bin这个目录?

回复 | 举报

小小百合2008-04-07 14:38:16

沙发

回复 | 举报
原创粉丝点击