Blog - HubSpot Product Team

Java library versioning for code access

Written by Yoav Shapira | Jun 26, 2009

Most code libraries have versions.  Versioning is one of those generally Good Things.

Yesterday @danmil and I were looking to see what specific Hadoop version was installed on a node in our EC2 cluster.

While Java has several mechanisms to specify library versions in a declarative way, especially when packaging a JAR or using a system like Maven, it doesn't seem like there's a standard for querying said version in code.

Hadoop has a command-line option to print out the version of the library.  There is a custom little Hadoop class, VersionInfo, with an annotation that specifies the version.

This is not bad.  It's useful, and it works.  Except yesterday, it said the version was unknown ;)

We eventually figured it out, we think, but the episode was interesting.

Is there some standard way to find the version of a Java library you're using, at runtime, from code?  Maybe something JMX-related?  If not, what's the best system you've seen?

Do other languages do better in this area?  What does Python or PHP do?  C#?

I'm not talking about a way for a sys admin to click around or view file versions.  It's a way for one piece of code (maybe in the same JVM, in the Java case, but not necesssarily).

http://dev.hubspot.com/bid/6007/Java-library-versioning-for-code-access