使用java反射运行时未找到HDFS拼花文件读取器DistributedFileSystem.class
我正在尝试使用java从远程HDFS文件系统读取拼花地板文件。我用拼花hadoop库来做这个 这就是我的代码的样子使用java反射运行时未找到HDFS拼花文件读取器DistributedFileSystem.class,java,reflection,hdfs,parquet,Java,Reflection,Hdfs,Parquet,我正在尝试使用java从远程HDFS文件系统读取拼花地板文件。我用拼花hadoop库来做这个 这就是我的代码的样子 public Map run( Map inputs ) { ... final Configuration conf = new Configuration(); conf.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName()
public Map run( Map inputs )
{
...
final Configuration conf = new Configuration();
conf.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
conf.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName());
conf.set("fs.defaultFS", "hdfs://" + connHostName + ":" + connPort);
conf.set("ipc.client.connect.timeout", "10000");
conf.set("ipc.client.connect.max.retries.on.timeouts", "3");
System.setProperty("hadoop.home.dir", "/");
Path path = new Path(filePath);
ParquetMetadata readFooter = ParquetFileReader.readFooter(conf, path, ParquetMetadataConverter.NO_FILTER);
MessageType schema = readFooter.getFileMetaData().getSchema();
...
}
下面是我正在使用的maven依赖项
<dependency>
<groupId>org.apache.parquet</groupId>
<artifactId>parquet-hadoop</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>3.1.0</version>
</dependency>
我尝试使用shaded插件并构建shaded jar,但问题仍然存在
我听说hadoop commons库使用Thread.currentThread.getClassLoader()加载类文件,这里似乎有问题
帮我把这个修好
提前谢谢。我自己找到了这个问题的解决方案 问题就在这里
ClassLoader child = new URLClassLoader(new URL[] { new URL("file://" + jarPath)}, ClassLoader.getSystemClassLoader());
我在这里加载系统类加载器,这导致从最终类路径中删除依赖库
我把它改成了
ClassLoader child = new URLClassLoader(new URL[] { new URL("file://" + jarPath)}, Thread.currentThread().getContextClassLoader());
这对我很有效。我自己找到了解决这个问题的办法 问题就在这里
ClassLoader child = new URLClassLoader(new URL[] { new URL("file://" + jarPath)}, ClassLoader.getSystemClassLoader());
我在这里加载系统类加载器,这导致从最终类路径中删除依赖库
我把它改成了
ClassLoader child = new URLClassLoader(new URL[] { new URL("file://" + jarPath)}, Thread.currentThread().getContextClassLoader());
这对我有用