You can find out what platform you are running on using the os.arch/os.name system property. See this answer to a similar question for more details.
As for loading the correct library, you could package each of the platform specific classes into their own jar and load them dynamically. See this question for an example of that.