ICE插件(slice2java eclipse plug-in)的安装及简单示例

本文介绍了如何安装ICE插件以及如何在Eclipse中使用slice2java工具。首先,从官方源下载Eclipse、ICE库和ICE Eclipse插件。接着,通过Eclipse的'Install New Software'功能来安装插件。

一.准备
1.Eclipse 请访问Eclipse官网下载
2.ICE库 请访问http://www.zeroc.com/下载
3.ICE eclipse插件 请访问http://www.zeroc.com/eclipse.html


二.安装
slice2java Eclipse plug-in的安装

From the Help menu, choose Install New Software

  • Click the Add button
  • Enter a name in the Name field, such as ZeroC
  • In the Location field, enter http://www.zeroc.com/download/eclipse
  • Click OK
  • Select the Slice2Java plug-in and click Next
  • Click Next again
  • If you agree to the license terms, check the box and click Finish






    选择一个版本进行安装如果先安装ICE库,插件会自动把设置中的slice2java路径设置好




    三.示例对比文档的示例,改变了输入参数的类型,而且添加了返回值

    1.slice文件新建一个工程,建立完成后,右键单击工程,会弹出如下菜单:



    选择红框菜单,在工程中加入插件支持,会使得.ice文件自动编译在新生成的slice文件夹中放入.ice文件,示例如下:

  • module gens
    {
    interface Printer
    {
    int printString(int a, int b);
    };
    };

    插件会在generated目录中生成必须的文件.



    2.servant类的PrinterI
    public class PrinterI extends _PrinterDisp { 
        @Override
    public int printString(int a, int b, Current __current) {
    // TODO Auto-generated method stub
         System.out.println(a + b);
    return a + b;

    }



    3.server端

    public class Server {
    public static void main(String[] args) {
    int status = 0;

    Ice.Communicator ic = null;
    try {
    ic = Ice.Util.initialize(args);
    Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints(
    "SimplePrinterAdapter", "default -p 10000");
    Ice.Object object = new PrinterI();
    adapter.add(object, Ice.Util.stringToIdentity("SimplePrinter"));
    adapter.activate();
    ic.waitForShutdown();
    } catch (Ice.LocalException e) {
    e.printStackTrace();
    status = 1;
    } catch (Exception e) {
    System.err.println(e.getMessage());
    status = 1;
    } finally {
    if (ic != null)
    ic.destroy();
    }
    System.exit(status);
    }
    }


    4.client端
    public class Client {

    public static void main(String[] args) {
    int status = 0;
    Ice.Communicator ic = null;
    try {
    ic = Ice.Util.initialize(args);
    Ice.ObjectPrx base = ic
    .stringToProxy("SimplePrinter:default -p 10000");
    PrinterPrx printer = PrinterPrxHelper.checkedCast(base);
    if (printer == null)
    throw new Error("Invalid proxy");

    int sum = printer.printString(1, 2);
    System.out.println(sum);

    } catch (Ice.LocalException e) {
    e.printStackTrace();
    status = 1;
    } catch (Exception e) {
    System.err.println(e.getMessage());
    status = 1;
    } finally {
    if (ic != null)
    ic.destroy();
    }
    System.exit(status);
    }
    }



    5.运行
    1.首先启动server
    2.启动client后,会在server的控制台窗口和client的控制台窗口出现打印信息


    求:怎么上传代码





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值