Reputation: 29966
I am trying to access hdfs from java app, but I got the error Incomplete HDFS URI, no host
.
Here is my core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
And here is my java code:
class AppTest {
private static final String HDFS_PATH = "hdfs:localhost:9000";
private static final String HDFS_USER = "hadoop";
private static FileSystem fileSystem;
@BeforeAll
public static void prepare()
{
try {
Configuration configuration = new Configuration();
configuration.set("dfs.replication", "1");
fileSystem = FileSystem.get(new URI(HDFS_PATH), configuration, HDFS_USER);
} catch (IOException e) {
e.printStackTrace();
} catch(InterruptedException e){
e.printStackTrace();
} catch(URISyntaxException e){
e.printStackTrace();
}
}
@Test
public void mkDir() throws Exception{
fileSystem.mkdirs(new Path("/hdfs-api/test/"));
}
@AfterAll
public static void destroy(){
fileSystem = null;
}
}
It always throw below error
java.io.IOException: Incomplete HDFS URI, no host: hdfs:localhost:9000
Upvotes: 0
Views: 1245
Reputation: 319
use netstat -tlpn | grep 9000 to check if the port is up
replace 127.0.0.1 with nodes real ip address, example: hdfs://192.168.10.1:9000
Upvotes: 2