Unfortunately there is no way around this... you will need to keep two copies of the class (one for each version). At build time, depending on the version of
Java detected,
Ant could build and include the appropriate class in the distribution.
More over, have you seen the
MockObjects Project? It provides many different mock objects, ranging from
JDBC to JMS (they provide different distributions depending on jdk and
servlet version). Give it a look, maybe you are reinventing the wheel here...