錯誤訊息:
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/shaded/org/apache/commons/collections/map/LinkedMap
at org.apache.hadoop.hdfs.shortcircuit.ShortCircuitCache.<init>(ShortCircuitCache.java:305)
at org.apache.hadoop.hdfs.shortcircuit.ShortCircuitCache.fromConf(ShortCircuitCache.java:376)
at org.apache.hadoop.hdfs.ClientContext.<init>(ClientContext.java:170)
at org.apache.hadoop.hdfs.ClientContext.get(ClientContext.java:216)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:405)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:308)
at org.apache.hadoop.hdfs.DistributedFileSystem.initDFSClient(DistributedFileSystem.java:204)
at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:189)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:3611)
at org.apache.hadoop.fs.FileSystem.access$300(FileSystem.java:174)
at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:3712)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:3663)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:557)
at org.apache.hadoop.fs.FileSystem$1.run(FileSystem.java:278)
at org.apache.hadoop.fs.FileSystem$1.run(FileSystem.java:275)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1899)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:275)
at hdfsutil.HdfsUtil.main(HdfsUtil.java:20)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.shaded.org.apache.commons.collections.map.LinkedMap
at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:359)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 20 more
我在使用 Hadoop 和 Java 時遇到一些問題,當我嘗試將檔案上傳至 HDFS 時發生錯誤。我將錯誤訊息提交給 ChatGPT,並收到回覆建議我需要安裝 commons-collections-4.4.4 的 JAR 檔(Hadoop 3.3.6 內建的版本是 commons-collections-3.3.2)。回覆中也建議我修改該 JAR 檔案的 pom.xml 依賴。
因此,我安裝了 commons-collections-4.4.4 的 JAR,但因為我使用的是 Java 專案,所以無法在 Eclipse 中編輯 pom.xml 文件。
其他資訊:
Hadoop 版本:3.3.6
Java 版本:JDK 1.8
Hadoop 部署在 Linux,並在 Windows 上使用 Java 客戶端 API。
程式碼:
請問要如何解決此問題,謝謝