windows下开发常见的异常(RPC)

来源:互联网 发布:大数据 云存储 编辑:程序博客网 时间:2024/06/02 06:07

实现RPC通信

首先介绍开发的过程  

Linux上进行开发

服务接口

public interface TestInterface {
public static final long versionID = 1L;
public String show();}

    服务实现类

public class TestImpl implements TestInterface{
@Override
public String show() {
// TODO Auto-generated method stub
return "abc"; }}

发布服务

public class StartService {
public static void main(String[] args) throws HadoopIllegalArgumentException, IOException {
Configuration conf=new Configuration();
Builder builder=new RPC.Builder(conf);
builder.setInstance(new TestImpl()).setBindAddress("Hadoop").setPort(10000).setProtocol(TestInterface.class);
Server build = builder.build();
build.start();
System.out.println("endpoint success");}}


windows开发客户端

需要复制一份服务接口

public interface TestInterface {
public static final long versionID = 1L;
public String show();}

调用服务方法

public static void main(String[] args) throws Exception {

TestInterface proxy = RPC.getProxy(TestInterface.class, 1L, new InetSocketAddress("192.168.229.128", 10000), new  Configuration());
System.out.println(proxy.show());

//访问hdfs文件系统

Configuration conf=new Configuration();
conf.set("fs.defaultFS", "hdfs://192.168.229.128:9000/");


}

最后就是一些常见运行不成功的问题

2016-11-23 21:21:19,511 ERROR [main] util.Shell (Shell.java:getWinUtilsPath(374)) - Failed to locate the winutils binary in the hadoop binary path
java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.

解决办法  没有找到winutils文件,在网上下载一个对应版本的hadoop-common-2.2.0-bin-master文件,解压之后,配置环境变量,如

HADOOP_HOME E:\大数据\hadoop-2.7.2

Path ;%HADOOP_HOME%\bin


Exception in thread "main" java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.createFileWithMode0(Ljava/lang/String;JJJI)Ljava/io/FileDescriptor;

原因:你的bin目录下的hadoop.dll文件和你的正在使用的hadoop  jar包不是同一个版本的,

解决办法:在网上下载一个对应版本的hadoop.dll文件替换原来的文件即可


最后补充一点:出错之后,每改动一处之后,重启IDE工具才能生效




0 1