一.准备
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 buttonEnter a name in the
Name field, such as
ZeroCIn the
Location field, enter
http://www.zeroc.com/download/eclipseClick
OKSelect the Slice2Java plug-in and click
NextClick
Next againIf 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的控制台窗口出现打印信息
求:怎么上传代码