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

2019-08-16 08:19发布

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

2条回答
Ridiculous、
2楼-- · 2019-08-16 09:12

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).

查看更多
手持菜刀,她持情操
3楼-- · 2019-08-16 09:13
  • 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");

查看更多
登录 后发表回答