3

I have been using com.apple.eawt to implement the OS-X About/Prefs/Exit items in the Application menu. This worked fine until Java 8. I can see com.apple.eawt in the JDK 1.8 library, but I can't seem to be able to access it.

I am using OS-X 10.13.6 and Java Version 1.8.0_201 and compiling with NetBeans 8.1.

Here's the code of a test app I wrote to show the problem:

package j8test;

import com.apple.eawt.*;

public class J8Test {
    public J8Test() {
        com.apple.eawt.Application.getApplication().setDockIconImage(null);

        System.out.println("*** OK ***");
    }

    public static void main(String[] args) {
        new J8Test();
    }
}

When I try to build it, I get the following errors:

   Compiling 1 source file to /Users/rcordes/Documents/TeamFlow/J8Test/build/classes
   /Users/rcordes/Documents/TeamFlow/J8Test/src/j8test/J8Test.java:4: 
   error: package com.apple.eawt does not exist
   import com.apple.eawt.*;
   /Users/rcordes/Documents/TeamFlow/J8Test/src/j8test/J8Test.java:10: 
   error: package com.apple.eawt does not exist
   com.apple.eawt.Application.getApplication().setDockIconImage(null);
   2 errors

Here is a screenshot of the NetBeans project:

Screenshot

piet.t
  • 11,718
  • 21
  • 43
  • 52
TeamFlow
  • 31
  • 5
  • Make sure that you have the Java 8 platform selected in your project properties, and aren't just compiling with Java 8 source compatibility. I think these features are supposed to work. – Radiodef Feb 12 '19 at 17:13
  • Both javac.source and javac.target are set to 1.8. I commented out the com.apple.eawt code and it compiled fine. When I run it, System.getProperty("java.version") returns "1.8.0_201". Is there anything else I can do? – TeamFlow Feb 12 '19 at 19:38
  • as far as I remember, that class along others were only available in the JDK which apple published for their macs, I guess that stopped with JDK 7 or 8, but I don't know of any replacement see also https://stackoverflow.com/a/13980873/1248724 – Zarathustra Feb 15 '19 at 07:14
  • Baed on my previous comment, one should be able to add the `ui.jar` from the 6/7 jdk to the classpath of your project and it should work – Zarathustra Feb 15 '19 at 07:23
  • 1
    Interesting. Adding `/Library/Java/.../rt.jar` to the classpath did not work. But when I copied that `rt.jar` into my project's space and added THAT to the classpath, it worked! Thanks for the hint. – TeamFlow Feb 15 '19 at 20:50

0 Answers0