IOException: No FileSystem for scheme: hdfs

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>> No FileSystem for scheme: hdfs

In this article, we show you how to package Maven dependent packages into jar packages. After using Maven assembly to create a jar, when providing this jar to other projects, the following error is reported:

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 for more info.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See for further details.
Exception in thread "main" No FileSystem for scheme: hdfs
     at org.apache.hadoop.fs.FileSystem.getFileSystemClass(
     at org.apache.hadoop.fs.FileSystem.createFileSystem(
     at org.apache.hadoop.fs.FileSystem.access$200(
     at org.apache.hadoop.fs.FileSystem$Cache.getInternal(
     at org.apache.hadoop.fs.FileSystem$Cache.get(
     at org.apache.hadoop.fs.FileSystem.get(
     at org.apache.hadoop.fs.FileSystem$
     at org.apache.hadoop.fs.FileSystem$
     at Method)
     at org.apache.hadoop.fs.FileSystem.get(
     at com.cetc.di.HDFSFileSystem.<init>(
     at callhdfs.Main.main(

However, in the project without a jar package, it can run normally. Through long-time observation and analysis, it is found that there are two packages related to Hadoop filesystem: hadoop-hdfs-2.7.1.jar and hadoop-common-2.7.1.jar. The services directory in meta-inf of these two packages has the following contents:

As you can see, there are org.apache.hadoop.fs.filesystem files in the services directory of both packages. When using Maven assembly plugin, all the dependent packages will be unpacked and then in the pack. In this way, the same file will be overwritten. Let’s see what is reserved in the typed package

As you can see, Maven assembly plugin (fatjar is the same), which puts the services content in hadoop-common.jar into the final jar package, while the services content in hadoop-hdfs.jar package is covered. Because our function call is written like this:

Used in the function hdfs://IP : port, but the implementation of this schema cannot be found in the generated final jar package. So it was thrown out No FileSystem for scheme: hdfs

The solution is to display and set this class when setting Hadoop configuration: “org. Apache. Hadoop. HDFS. Distributed file system:

configuration.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");

Then it’s repackaging and everything works OK

The contents of services file in meta-inf in jar package involve the concept of servicelocator

For a detailed introduction, see the official JAVA document:

Check out this article to see how servicelocator works

Recently, several project modules need to be upgraded from Hadoop 1 to Hadoop 2, but there are some problems in the process of modification, one of which is using file system FS = file system. Get (CONF); Call HDFS and report an error. The specific error information is as follows:

Look at the file system class. It is found that when initializing through file system. Get(), it needs to be implemented by static loading. The specific implementation is as follows:

It can be seen from the code that the getfilesystem class (string scheme, configuration CONF) method needs to be called finally. In this method, the configuration information of “FS.” + scheme + “. Impl” (in this case, FS. HDFS. Impl) defined in the core-default.xml file needs to be read, However, this configuration information is not configured in the default configuration file (core-default.xml file in hadoop-common-x.jar)



Add the following configuration information to the configuration file core-default.xml:

 <description>The FileSystem for hdfs: uris.</description>

After the program is packaged as a jar, it is executed on the server. The program can execute correctly as expected, but it is still very uncomfortable to see the following errors:

Java code


[problem analysis:]
after eclipse is packaged, the following two configuration items do not exist in the core-site.xml configuration file in the jar package


just add the above two configurations to the core-site.xml, replace the XML in the jar package, and throw it back to the server, and it will run successfully

Similar Posts: