先编一个idl文件,如:person.idl
module person{
interface hand{
int add(int x,int y);
}
}
然后用idl2java.exe文件编译person.idl文件
idl2java person.idl
产生一个目录person
里面有一个文件hand.java,这里定义了一个接口interface hand
应该编一个类去实现这个接口handImpl.java
public class handImpl extends _handImplBase implements
hand{
int x,y;
public handImpl(){
x=0;
y=0;
}
int add(int x,int y){
this.x=x;
this.y=y;
return (x+y);
}
}
总之在handImpl中实现各种功能。
接下来讲端编程:Server.java
package person;
public class Server{
public static void main(String[] argv){
org.omg.CORBA.ORB
orb=org.omg.CORBA.ORB.init(args,null);
org.omg.CORBA.BOA boa=orb.BOA_init();
person.hand p=new
person.handImpl("Person.hand");
boa.obj_is_ready(p);
System.out.pritnln(p+ " is ready.");
boa.impl_is_ready();
}
}
如果路径设置对的话,用命令java Server就行了,不过要先运行smart
agent
public class Client{
org.omg.CORBA.ORB orb;
person.hand p;
public static void main(String[] argv){
Client app=new Client();
orb=org.omg.CORBA.ORB.init(args,null);
p=person.handHelper.bind(orb,"Person.hand");
int result=p.add(20,30);
System.our.pritnln(result);
}
}
编译用命令javac person\*.java
阅读(676) | 评论(1) | 转发(0) |