how can I develop Apple Java Extensions on Windows?
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开发者_StackOverflow社区 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.
I created an updated jar to solve this problem. GitHub source here. It's hosted on maven central
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.
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.
The latest can be downloaded from http://developer.apple.com/library/mac/samplecode/AppleJavaExtensions, click on the "Download Sample" button at the top of the page
The latest documentation is at
http://developer.apple.com/library/mac/documentation/Java/Reference/JavaSE6_AppleExtensionsRef/api/index.html?com/apple/eawt/Application.html
精彩评论