Find the location of hive-site.xml in java code

左心房为你撑大大i 提交于 2020-01-07 03:05:39

问题


I want to pass the location of hive-site.xml file in my java program.

What is the best way to find out the location of this file automatically in java code?

I do not want to hard code the path to /etc/hive/conf/hive-site.xml for cloudera distibution


回答1:


By default the Hadoop Configuration constructors search for "blahblah-site.xml" config files in directories present in CLASSPATH. If it doesn't find them, then it reverts to hard-coded "default" values, without any warning (!).

So make sure that the CLASSPATH contains the appropriate directories on the front, e.g. /etc/hadoop/conf/:/etc/hive/conf/:/etc/tez/conf/:...

Then the only thing you have to do in your Java code is to check that critical properties are set up with something else that hard-coded defaults (and raise a PleaseSetupProperClasspathYouSuckerException if it's not the case).




回答2:


  • Set the HIVE_HOME path as /etc/hive/bin in the system environment variable and get it in java code as follows,

String path = System.getenv("HIVE_HOME");



来源:https://stackoverflow.com/questions/33901667/find-the-location-of-hive-site-xml-in-java-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!