1

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?

Community
  • 1
  • 1
Ian Leslie
  • 841
  • 1
  • 9
  • 25
  • Humm interesting I do not think I actually have a JDK on this machine. That would be bad. However I cannot find a 1.6 JDK to down load. If the only option is to just go with 1.7 and move on I will have to consider that. Scratch that there is a JDK on here and Eclipse knows about it. My impression came from the terminal java -version – Ian Leslie May 22 '14 at 15:07

1 Answers1

3

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


.

enter image description here

martinez314
  • 12,162
  • 5
  • 36
  • 63
  • Good thought on the stubs still in the path but no. On my Mac I have a clean install of Eclipse and just a sample app that I took from a tutorial and modified. The issue I am having is that there are no AppEvent, OpenFilesHandler present in any class path. Now having said that after copying your sample code (thanks for that BTW) I see the following error during compilation in Eclipse "Access restriction: The type OpenFilesHandler is not accessible due to restriction on required library /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar" – Ian Leslie May 22 '14 at 20:26
  • Bummer, when I look at the access restrictions on ui.jar there is no mention of com.apple.eawt* However when I look at the contents of the .jar there they are. All the stuff I need. So that leaves me with - what on earth is the correct way to make this available to my application? Thanks for the additional info - I now have more things to search with. – Ian Leslie May 22 '14 at 20:30
  • @IanLeslie Sounds like there is some configuration issue with your Eclipse. See my screenshot above for what I see. Note, this should be the default configuration. I didn't have to change anything to get this to work. – martinez314 May 22 '14 at 20:41
  • Thanks @whiskeyspider. I think you are correct about the configuration issue. My JRE definition panel looks exactly the same as yours - build number and all. However I am running 10.9.2 if that makes any difference. I will look at the configuration angle and hope to get to try your sample code soon. – Ian Leslie May 23 '14 at 13:41
  • OK first some good news. I was able to get this to compile under Eclipse finally by adding access rules to the project. Under the build path the jvm has access rules that forbid the use of the com.apple package and sub packages. I added an access rule "com/apple/eawt/**" and now Eclipse is happy to compile the code. – Ian Leslie May 28 '14 at 10:00
  • Then some bad news. Your example did no work for me. I instantiated your example class in my main before the event loop and added System.out.println statements to the about, preference and quit handler methods. But they never get called. Not sure what is going on. My app is an SWT app but I do not see how that matters, but I suppose it could. – Ian Leslie May 28 '14 at 10:00