When I do multi-platform testing on Windows it gets annoying that Eclipse shows errors in the project because of the com.apple.eawt code that I have in a special Mac customization task. Worse yet, if I export a runnable jar on Windows, it won't run on mac because of the unresolved compilation problems. What's the best way to let Windows Java and com.apple.eawt live in peace? I can't see how I would be able to spin off the code to a jar, since it requires access to lots of the program's state. Thanks for your help!
This looks like it could be what you're after: http://developer.apple.com/mac/library/samplecode/AppleJavaExtensions/
"This is a pluggable jar of stub classes representing the new Apple eAWT and eIO APIs for Java 1.4 on Mac OS X. The purpose of these stubs is to allow for compilation of eAWT- or eIO-referencing code on platforms other than Mac OS X."
You might be able to use the approach taken in OSXAdapter, the "dynamic implementation [of which] will only be triggered on platforms that actually support the Apple APIs (e.g. Java 1.4 or later on Mac OS X), avoiding any compatibility concerns." A sample application and the adapter itself are available, as mentioned in this article.
Put the OS X specific code in a separate class.
In your main code, use reflection to see if one of the Apple classes are present (or a Class.forName), and if so, THEN invoke the separate class above. I cannot remember if you can do that safely just by calling it, or you need to invoke the separate class by reflection too.