Support Questions

Find answers, ask questions, and share your expertise
Celebrating as our community reaches 100,000 members! Thank you!

Cannot connect to hdfs through java. My hadoop version 2.9.0. Code and error are as following

import org.apache.hadoop.conf.*;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class HdfsCon 
	public static void main(String[] args) throws Exception 	 
		String HdfsUrl="hdfs://";
		Configuration conf=new Configuration();
		URI uri=new URI(HdfsUrl);
		FileSystem fs= FileSystem.get(URI.create(HdfsUrl),conf);
		String fp="/home/user1/Documents/hive-site.xml";
		String tp="/fifo_tbl";
		fs.copyFromLocalFile(new Path(fp),new Path(tp));

It gives me following Exception........

Exception in thread "main" org.apache.hadoop.ipc.RemoteException: Server IPC version 9 cannot communicate with client version 4
	at org.apache.hadoop.ipc.RPC$Invoker.invoke(
	at com.sun.proxy.$Proxy1.getProtocolVersion(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at com.sun.proxy.$Proxy1.getProtocolVersion(Unknown Source)
	at org.apache.hadoop.ipc.RPC.checkVersion(
	at org.apache.hadoop.hdfs.DFSClient.createNamenode(
	at org.apache.hadoop.hdfs.DFSClient.<init>(
	at org.apache.hadoop.hdfs.DFSClient.<init>(
	at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(
	at org.apache.hadoop.fs.FileSystem.createFileSystem(
	at org.apache.hadoop.fs.FileSystem.access$200(
	at org.apache.hadoop.fs.FileSystem$Cache.get(
	at org.apache.hadoop.fs.FileSystem.get(
	at HdfsCon.main(


Cloudera Employee

Hello @Saurabh Ambre,

The error message you are getting is caused by a version mismatch between the client library you are compiling with and the server version of HDFS running.

e.g. Using version 3.1 of the client JARs with version 2.7 of the server.

==> What version of HDP are you using?

Hortonworks provides Maven repos you can use in your Java IDE to facilitate getting the correct librairies. See here :