ICE 初始用之java经验教训例子
转载自:http://joeywanghome.spaces.live.com/blog/cns!ddf8393aef49368b!163.entry?wa=wsignin1.0&sa=984310076
只为自己日后翻阅方便,不做他用,特此声明
这个项目涉及两种语言,c++和java。使用ICE中间件。其中有一部分就是java通过ICE调用后台的由c++实
现的函数。java端调用的过程是这样的:
1。定义好接口,文件类型全部是*.ice文件。(在这个项目中这部分是C++同志完成的)
2。执行slice2java -I. XXX.ice。ICE将自动将其编译成.java文件。(参见注释1)
3。取所有生成的java文件到本地,放到相应的package里面。(参见注释2)
4。把ICE.jar放在lib里面。
5。编译java文件,生成class。
6。配置Config文件,联接ICE时使用。(参见注释3)
7。在自己的类里面实现ICE调用。(参见注释4)
8。完成任务!
其他问题(参见注释5)
在这一系列的过程中可能会出现很多问题,我将我在各个阶段遇到的问题进行了一些总结,供参考:
注释1:
直接执行slice2java wasptrans.ice。当时报了一大堆错误,例如:
wasptrans.ice:7: No include path in which to find wasp.ice
wasptrans.ice:20: `FeeWay' is not defined
wasptrans.ice:30: `UserInfo' is not defined
wasptrans.ice:31: `ProductInfo' is not defined
......
即找不到wasp.ice里面定义的许多类。
后来用slice2java -I. wasptrans.ice就可以解决这个问题。 “-I” 是告诉编译器在编译的时候要包含
路径,“.”指当前目录。合在一起“-I.” 就相当于指定当前目录也是其在编译过程中查找的路径。还
有其他多种参数可以在编译的时候使用,可以用slice2java -h进行查看。
mqq@dev_bj_kevinzhao:~/wasp/interface$ slice2java -h
Usage: slice2java [options] slice-files...
Options:
-h --help Show this message.
-v --version Display the Ice version.
-DNAME Define NAME as 1.
-DNAME=DEF Define NAME as DEF.
-UNAME Remove any definition for NAME.
-IDIR Put DIR in the include file search path.
--output-dir DIR Create files in the directory DIR.
--tie Generate TIE classes.
--impl Generate sample implementations.
--impl-tie Generate sample TIE implementations.
--depend Generate Makefile dependencies.
-d --debug Print debug messages.
--ice Permit `Ice' prefix (for building Ice source code only)
--checksum CLASS Generate checksums for Slice definitions into CLASS.
--stream Generate marshaling support for public stream API.