类路径中的分布式缓存jar,但获取classnotfoundexception

u91tlkcl  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(462)

使用hbasetestinguility,我将启动一个小型集群。

  1. testUtil = new HBaseTestingUtility(configuration);
  2. testUtil.startMiniCluster();

并提供我的jar以放置在distributedcache的类路径中

  1. final String aJarResourcePath = Thread.currentThread().getContextClassLoader()
  2. .getResource("abc/a-1.0.jar").getPath();
  3. final FileSystem fs = FileSystem.get(configuration);
  4. final Path pathToArtifacts = new Path("/Runtime/a-artifacts");
  5. fs.mkdirs(pathToArtifacts);
  6. fs.copyFromLocalFile(new Path(aJarResourcePath), pathToArtifacts));
  7. DistributedCache.addFileToClassPath(disqualified, configuration);

在我的mapfn上,我使用的是jar a-1.0.jar。我能在Map上看到jar

  1. final Path[] fus = DistributedCache.getFileClassPaths(config);

所以我认为jar在类路径中并指向hdfs位置,但是我在尝试创建对象时遇到了classnotfoundexception。我不知道发生了什么,请帮忙。

lvmkulzt

lvmkulzt1#

我不知道这是否是你的问题的原因,但是2个参数过载 addFileToClasspath 在hadoop 1.2.1中已弃用(实际上,在hadoop2.7.2中 DistributedCache 类已全部弃用!)javadocs没有说明为什么这个方法被弃用,所以很难知道这是否是问题所在。
更新
更多的研究表明,您的问题实际上可能是jar文件没有被扩展。尝试使用 addArchiveToClasspath 相反。

相关问题