简体   繁体   中英

How do I make use of the apple extensions for Java using Eclipse

I can import the package but none of the classes appear to be there. On the other hand I also cannot find documentation either.

I have been struggling to get my Java application working properly on the MAC. I had been using Windows to develop and I did not have access to a MAC so I had a little help from some volunteer testers. The trouble is the Apple Java extensions. It took me a while to find out they even existed and then I found (through here) about stub libraries to allow development on windows. But it never worked for my testers. I broke down and bought a used Mac figuring it would have it solved in hours. Joke is on me I am still stuck:-)

I have found lots of information but I still cannot get things to work.

Various sites and tutorials have pointers like this question to non existent docs on Apples web site: https://stackoverflow.com/questions/21512843/api-docs-for-apple-eawt-java-extensions

Sounds like Oracle has taken over the libraries etc but I am using Java 1.6. I would prefer to have my app work with 1.6 and up so I am hoping to get this to work with the JDK my mac has installed. Can Java 7 use Apple Java Extensions?

And of course it turns out the tutorials I found are using deprecated API. But again the links to the api docs are broken: What's the alternative to using the now deprecated com.apple.eawt.ApplicationAdapter in Java Swing apps on the Mac?

Right now in my Eclipse IDE I can import com.apple.eawt and things seem happy how ever none of the classes I expect to be there can be found. What am I missing? Is Mac development always this hard?

about stub libraries to allow development on windows

You don't by chance have the stub libraries in your classpath? The stub library is meant to be used only on an OS other than OS X. Otherwise, you might hit a runtime error when running the same code on Windows. Be sure you don't include the stub library on your classpath when running in OS X, but do when running in Windows.

What's the alternative to using the now deprecated com.apple.eawt.ApplicationAdapter in Java Swing apps on the Mac?

Here's an example:

public class AppleHandler implements com.apple.eawt.OpenFilesHandler, com.apple.eawt.AboutHandler, com.apple.eawt.PreferencesHandler, com.apple.eawt.QuitHandler,
        com.apple.eawt.OpenURIHandler {



    public AppleHandler() {
        com.apple.eawt.Application app = com.apple.eawt.Application.getApplication();
        app.setAboutHandler(this);
        app.setPreferencesHandler(this);
        app.setQuitHandler(this);
        app.setOpenFileHandler(this);
        app.setOpenURIHandler(this);
    }



    @Override
    public void openFiles(com.apple.eawt.AppEvent.OpenFilesEvent ofe) {

    }



    @Override
    public void handleAbout(com.apple.eawt.AppEvent.AboutEvent ae) {

    }



    @Override
    public void handlePreferences(com.apple.eawt.AppEvent.PreferencesEvent pe) {

    }



    @Override
    public void handleQuitRequestWith(com.apple.eawt.AppEvent.QuitEvent qe, com.apple.eawt.QuitResponse qr) {

    }



    @Override
    public void openURI(com.apple.eawt.AppEvent.OpenURIEvent oue) {

    }
}

Edit: I am using Java 6 on OS X 10.8. Here is how I see my JDK in Eclipse


.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM