In his blog, Daniel Fuchs has published the source code for a generic JMX client.