Hadoop 用命令行編譯URLCat
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
import org.apache.hadoop.io.IOUtils;
public class URLCat {
static{
URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
}
public static void main(String args[]) throws Exception{
InputStream in = null;
try{
in = new URL(args[0]).openStream();
IOUtils.copyBytes(in, System.out, 4096, false);
}finally{
IOUtils.closeStream(in);
}
}
}
編譯
javac -classpath hadoop-core-1.1.2.jar -d secondProject secondProject/URLCat.java
生成JAR
jar -cvf URLCat.jar -C secondProject/ .
hadoop jar URLCat.jar URLCat hdfs://localhost:49000/user/hadoop/input/file01
路徑根據
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:49000</value>
</property>
調整
更多Hadoop相關信息見Hadoop 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=13