You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mapreduce-user@hadoop.apache.org by Steve Lewis <lo...@gmail.com> on 2014/02/09 23:26:56 UTC
How do I determine in my Java code which version of Hadoop I am running
In 1.o I could say but this does not seem to work in 2.0 and has compile
issues in 0.2
So surely there is a SIMPLE way for my code tr determine the Hadoop version
Here assume HadoopMajorVersion is an enum
private static private static HadoopMajorVersion getHadoopVersion() {
// force the class loader to load a class in the package so we can
read the package
Class hadoopVersionAnnotation = HadoopVersionAnnotation.class; //
make cure the class loader know about packages
Package aPackage = Package.getPackage("org.apache.hadoop");
if(aPackage == null)
return Version0;
HadoopVersionAnnotation annotation = (HadoopVersionAnnotation)
aPackage.getAnnotation(HadoopVersionAnnotation.class);
if(annotation == null)
return Version0;
String version = annotation.version();
HadoopMajorVersion[] versions = values();
for (HadoopMajorVersion v : versions) {
if(version.startsWith(v.getStartText()))
return v;
}
throw new IllegalStateException("Unknown Hadoop version " +
version);
}
--
Steven M. Lewis PhD
4221 105th Ave NE
Kirkland, WA 98033
206-384-1340 (cell)
Skype lordjoe_com