我正在尝试使用Java从远程HDFS文件系统读取镶木地板文件。我为此使用了镶木地板库。
这就是我的代码的样子,
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();
...
}
以下是我正在使用的专家依赖项,
<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>
另外,我尝试添加2个依赖,hadoop核心和hadoop hdfs
当我在上面运行镶木地板阅读器代码时,它的工作正常,我面临的问题是当我作为反射运行时。
我用它创建了一个胖罐,并向其他程序提供类名以及jar,该程序将使用反射运行。
反射代码如下所示,
String packageName = "com.mycompany.hdfs.parquet.Parquet";
String jarPath = "/Users/.../hdfs-parquet-reader/target/hdfs-parquet-reader-0.0.1-jar-with-dependencies.jar";
ClassLoader child = new URLClassLoader(new URL[] { new URL("file://" + jarPath)}, ClassLoader.getSystemClassLoader());
Class classToLoad = Class.forName(packageName, true, child);
String inputParamsString = "{}";
Object obj = classToLoad.newInstance();
当我运行上面的代码时,我得到分布式文件系统.class找不到在行,ParquetMetadata readFooter = ParquetFileReader.readFooter(conf, path, ParquetMetadataConverter.NO_FILTER);
我构建了胖罐,验证的罐子包含类组织.apache.hdfs.分布式文件系统.class存在于罐子中。
另外,我验证了java -cp.jar类名.class是否按预期工作。
皈依舞
相关分类