I realise that the two Java versions are substantially different but the library I am looking to write uses standard HTTP/TCP networking and data collections to perform it's task. These are two abilities that both platforms provide, albeit to different scopes. I assume that I could write a library that works with the lowest common denominator but it would be ideal to have a Java SE version that exploits the benefits of generics and the more extensive data collections at the very least.
I am hoping that I can maintain a code base that shares as much code as possible between the two versions of the library, using a build script to produce a separate library for each of the Java platforms. The APIs will obviously differ slightly but if the core business logic of the library can be shared that would save time and effort.
Are their any build script/pre-processing/other techniques I can utilise to achieve this goal? Is this more hassle then it is worth?
Probably yes.
Preprocessing is generally frowned upon in the Java world. Preprocessors do exist, but you tend to find that they are not well supported in IDEs, build tools, etc.
For something like this, I'd recommend the following approach:
Figure out how much the actual differences are between the SE and ME versions of the code there really need to be. From a long term maintenance perspective, you probably want no differences at all.
If there are things that you simply cannot deal with using the least common denominator approach, then factor them out and design / implement an internal API that hides the platform differences. By hand.
Also, consider doing things like porting useful libraries from SE to ME. For example, if you really need a full collections stack, see if you can find a port of the SE Collections framework to ME. (But the downside of this is likely to be code bloat on ME ... and that won't make you popular.)