eclipse上单步调试Hive

在百度找到这篇文章:在Windows eclipse上单步调试Hive教程 可是我死活搞不定在windows安装hadoop和hive,cgywin不靠普啊。。还是在ubuntu下调试了。

准备

前提条件是你已经部署好hadoop和hive,能够正常的执行hive查询。 我在~/workspace/hive新建了两个目录lib和conf

  1. 从hive目录中的lib和hadoop目录中的lib复制一份到一个目录里,我是放在~/workspace/hive/lib
  2. 还要把hadoop目录下的hadoop*.jar都拷贝过来吧。
  3. 如果用mysql做metastore的数据库,还需要把mysql-connector的lib加上
  4. 把hive的conf文件夹拷贝过来(要已配置好的conf文件哦)
  5. 把hive中的src目录拷贝进来

创建项目

在这个目录下(~/workspace/hive/src/cli)的代码是hive命令行的代码,我们可以通过调试它来了解hive的执行过程。 在这个目录下,用eclipse新建一个项目。 配置bulid path,把我们准备好的lib全部加上 这个时候,代码应该没有编译错误了,如果有,请检查一下那个lib没加上。 还有个重要的步骤!hive是怎样找它的配置文件的呢? 我们要把conf目录加入classpath中,在debug configuration中的Classpath,点击左侧的advanced,add exteral path,选上我们准备好的conf目录。 这样就可以开始debug了! 如果你运行报does not have a sch错误,应该是由于没找到配置文件引起的。
  顺便看看hive是怎么找到配置文件的。
都是通过getClassLoader().getResource()方法来获取的,所以配置文件夹必须在classpath中!

URL hconfurl = getClassLoader().getResource("hive-default.xml");
    if (hconfurl == null) {
      l4j.debug("hive-default.xml not found.");
    } else {
      addResource(hconfurl);
    }
    URL hsiteurl = getClassLoader().getResource("hive-site.xml");
    if (hsiteurl == null) {
      l4j.debug("hive-site.xml not found.");
    } else {
      addResource(hsiteurl);
    }
updatedupdated2023-12-062023-12-06