標籤:http java os 檔案 io art
String home = "hdfs://192.168.0.212:8020/";
String src = "/root/案頭/111.jpg";
String dst = "/6.jpg";
InputStream in = new BufferedInputStream(new FileInputStream(src));
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(home), conf);
OutputStream out = fs.create(new Path(home+dst));
IOUtils.copyBytes(in, out, 4096, true);
System.out.println("success");
這段代碼在main方法中執行沒有問題,順利通過,但是將這段代碼放到Servlet的doGet方法中啟動時出問題,
應該跟http://www.hadoopor.com/thread-1724-1-1.html是一個問題,根據這篇文章最下面的方法,將那三個jar包加到CLASSPATH解決不了,還是拋異常,
主要異常如下
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/test]]
Caused by: java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration
PS:hadoop-common-2.2.0.jar已經引入了,用的跟在main方法是一樣的jar包
有org/apache/hadoop/conf/Configuration
全部都是hadoop2.2.0中的jar包,main方法直接運行成功,jar包應該不會有什麼問題,主要是web項目,項目啟動的時候報錯,不清楚原因,
已經確認hadoop-common-2.2.0.jar
中存在org/apache/hadoop/conf/Configuration,項目中也能引入org.apache.hadoop.conf.Configuration,