c、java和hadoop文件的编译执行
一、gcc多文件编辑
准备文件:main.c、 hello.c、 hello.h
1 /*=====main.c=======*/ 2 #include <stdio.h> 3 #include "hello.h" 4 int main() 5 { 6 hello(); return 0; 7 } 8 /*====hello.c=======*/ 9 #include <stdio.h> 10 #include "hello.h" 11 void hello() 12 { 13 printf("Hello,world!.\n"); 14 } 15 /*===hello.h=======*/ 16 void hello();
四种方法:
1、分别编译:gcc -c main.c gcc -c hello.c gcc main.o hello.o -o One ./One
2、联合编译:gcc main.c hello.c -o One ./One
3、建库:gcc -c main.c hello.c ar crv Mylib.a hello.o gcc -o One main.o Mylib.a ./One
4、创建makefile文件(多一个hi试试):make ./One
One:main.o hello.o hi.o gcc main.o hello.o hi.o -o One -lm main.o:main.c hello.h hi.h gcc -c main.c hello.o:hello.c hello.h gcc -c input.c hi.o:hi.c hi.h gcc -c hi.c clean: rm -f *.o One
二、Java编译
1、①编译 javac hello.java 在该目录生成hello.class, ②java hello执行
2、参数-cp和-d: -d只用在javac 定向生成.class的位置,-cp制定类运行时 依赖的其他类或jar包的目录,多个包用冒号:间隔,eg:
1 javac -d /home/xu Person.java 2 java -cp .:c:\work\my.jar;c:\work\*.jar packname.mainclassname 3 java -cp .:/home/myuser/work/lib/my.jar:/home/myuser/work/dependency_jars/*.jar packname.mainclassname
三、hdfs的shell命令 (看这位仁兄的吧) 附Hadoop文档 cmd下常用命令
格式:hadoop fs -ls /hdfs-path-file
递归lsr /path 查看cat /file 输出text /file 文件大小du /path 创建touchz /file 权限chmod -R 777 /path
创建目录mkdir /dir 移动命名mv /file1 /file2 删除rm /file 、rm /emptydir 递归删除rmr /dir
复制到本地get /file /localfile 本地上传put /localfile /file
四、虚拟机本地与hdfs数据互动
import java.io.InputStream; import java.net.URI; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.*; import org.apache.hadoop.io.IOUtils;
public class HadoopTest { public static void main(String[] args) throws Exception { // 参考文章
Configuration conf = new Configuration(); FileSystem fs = FileSystem. get(URI.create (args[0]), conf); InputStream in= fs.open( new Path(uri)); IOUtils.copyBytes(in, System.out, 4096, false); IOUtils.closeStream(in); } }
准备测试文件src.txt(随便写点什么),上传云端 hadoop fs - put src.txt /usr/;
编译:javac -cp .:/usr/hadoop-2.6.5/share/hadoop/common/hadoop-common-2.6.5.jar HadoopTest.java
执行:hadoop HadoopTest /usr/src.txt
2019-07-18 15:42:05

浙公网安备 33010602011771号