Hadoop 用命令行编译URLCat

2019-03-28 12:56|来源: 网络

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

相关问答

更多
  • 在Master节点上执行 hdfs namenode -format ,如果没有error和Exception 表示格式化成功,这个命令如果刚开始的话可以用,而且不能使用多次,后面最好不要用这个命令,比如我新增加一个slave节点以后,使用两次这个命令之后,发现文件系统坏掉了, 最后发现在格式化的时候,把 hdfs元数据存放的地点文件里面的版本池ID改变了, 于是我将这两个ID改为相同之后才可以用, 所以你搭建集群时用这个命令就可以了, 以后用到的话,有可能造成文件的丢失,和文件系统的异常。
  • 如果你已经进入hadoop/bin目录下,应该是 ./hadoop fs -mkdir /input 如果你没有进入hadoop/bin目录,你应该打全路径或相对路径 假设你的hadoop安装在/home/hadoop下,你可以打 /home/hadoop/bin/hadoop fs -mkdir /input 一般情况下你都在/home/hadoop默认目录下,你可以打 bin/hadoop fs -mkdir /input
  • $Hadoop=`which hadoop`; #这里加上一句 print "$Hadoop fs -get .....\n"; `$Hadoop fs -get ......`; 看看打印出来的命令是不是你想要的,如果是你想要的,就手动执行一遍。 有问题继续追问。
  • 一般命令行参数需要在main函数中获取,然后添加入job中,在map类中,重写configuration方法,将参数赋值给一个私有变量,map函数就可以调用了
  • 它是实现正确的接口还是为reducer实现扩展正确的类。 例外情况表明实现方法中的包差异与使用相比(新旧vso hadoop api) Is it implementing the correct interface or extending the correct class for the reducer implementation. The exception says a package difference in the implementation method required vs the ...
  • 这取决于程序中使用的依赖项。 基本的hadoop程序需要hadoop-commons-version.jar和hadoop-core-version.jar 。 使用以下内容 javac path-to/*.jar:path/to/*.jar classname.java This depends on the dependencies used in the program. Basic hadoop-program require hadoop-commons-version.jar & hadoop ...
  • 看起来你必须从Hive中转储它。 这似乎是这个问题的重复 - 如何在Linux中查看Hive orc文件的内容 根据您的Hive版本, hive --orcfiledump 或类似的东西应该这样做。 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+ORC Looks like you'll have to dump it from Hive. This appears to be a ...
  • 看起来你正在使用hadoop的后级版本。 检查您的图形构建器版本所需的hadoop版本,并确保它是您正在运行的版本。 Looks like you're using a back level version of hadoop. Check the version of hadoop that your version of graph builder needs and make sure that's the version you're running.
  • 您需要在user之前添加/ : bin/hadoop jar /user/asiapac/bmohanty6/wordcount/wordcount.jar WordCount /user/asiapac/bmohanty6/wordcount/input /user/asiapac/bmohanty6/wordcount/output 这使它们成为完全合格的路径。 如果省略/在user之前,Hadoop将从当前目录中搜索。 You need to add / before user: bin/hadoo ...
  • 我按原样使用了您的代码,并在进行了3次修改后进行了编译: 在以下语句中,将filename更改为fileName ( fileName 'N'大写) 更改: word.set(itr.nextToken().toLowerCase().replaceAll("[^a-z]+","") +" "+ filename); 至: word.set(itr.nextToken().toLowerCase().replaceAll("[^a-z]+","") +" "+ fileName); 导入的包Gene ...