12

I'm using Max OS X Mountain Lion, java -version returns "1.6.0_37". But I cannot compile project with com.apple.eawt.* classes imported.

What I have to install to have Apple Java Extensions on my system?

Any help would be appreciated!

Update:

I receive following error from compiler:

java: package com.apple.eawt does not exist

Update-2:

XCode version 4.5.2 is installed

Update-3:

The reason of my problem was missed ui.jar in classpath. Thanks to @Ian Roberts

Alexander Kuznetsov
  • 533
  • 1
  • 5
  • 13

4 Answers4

6

There is no JAR to download or anything extra to install, the classes are part of the JDK on Mac OS X. In Apple Java 6 JDKs they live in Contents/Classes/ui.jar under the JDK bundle (e.g. /System/Library/Java/JavaVirtualMachines/1.6.0.jdk or /Library/Java/JavaVirtualMachines/1.6.0_37-b06-434.jdk), on Oracle Java 7 they are in lib/rt.jar under the JRE home directory (/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home or /Library/Java/JavaVirtualMachines/jdk1.7.0*.jdk/Contents/Home/jre).

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
  • Thank you! Ui.jar was missed in classpath. – Alexander Kuznetsov Dec 20 '12 at 21:44
  • 1
    how to add this to maven compiler plugin? i am new to maven can you please help me. – Mubasher Nov 02 '14 at 07:41
  • @Mubasher if you're compiling on a Mac it should work out of the box, if you're not on Mac then you either need to write your code to make the necessary calls by reflection ([example](http://sourceforge.net/p/gate/code/HEAD/tree/gate/tags/release-8.0/src/main/gate/gui/MainFrame.java#l1721)) or compile against a stub jar with no-op implementations of the relevant methods, such as http://ymasory.github.io/OrangeExtensions/ – Ian Roberts Nov 02 '14 at 12:29
  • @IanRoberts yeah i am compiling over Mac, compilation of source files failed and specifically on the class where i am using the aewt.Application code. i tried to add dependency by manually extracting rt.jar file from JDK home/jre directory. now this way it is working – Mubasher Nov 02 '14 at 14:16
  • This helped me decompile some old software. I used the rt.jar found in `jdk1.8.0_261.jdk` on Big Sur. – I'll Eat My Hat Feb 13 '21 at 23:48
  • on Big Sur, look for /Library/Java/JavaVirtualMachines – Konchog May 10 '21 at 14:07
5

Solution for Java 9 and later

In JDK 9, internal APIs such as those in the Mac OS X com.apple.eawt package will no longer be accessible.

see: http://openjdk.java.net/jeps/272

com.apple.eawt has been replaced.
Some of the features are covered here: https://docs.oracle.com/javase/9/docs/api/java/awt/Taskbar.html

An example implementation of setting the dock icon in mac os can be found here:
https://stackoverflow.com/a/56924202/5276779

flohall
  • 967
  • 10
  • 19
  • 1
    Not all of the com.apple.eawt features appear in the java desktop, it's not really been replaced totally. If you want access to the gestures from the touchpad you need com.apple.eawt.event, which is hidden away, see https://stackoverflow.com/questions/48535595/what-replaces-gestureutilities-in-java-9 on how to get them working. – Hamish258 Feb 05 '22 at 20:19
0

Just in case you're still looking and anyone else hits this, the MacOS GestureUtilities are still available for that platform. See What replaces GestureUtilities in Java 9

Hamish258
  • 305
  • 2
  • 9
-1

Just like any other external library, you have to add the JAR containing those classes to your classpath. Just because you are running on a Mac does not mean the stock Java JDK is 'extended' -- otherwise, it would not be truly platform-independent.

Thorn G
  • 12,620
  • 2
  • 44
  • 56
  • Could you please provide me a link or at least a google search request to get a URI to download such JAR? I cannot find it. – Alexander Kuznetsov Dec 20 '12 at 21:23
  • That's not actually true. The JDK that apple makes available for a Mac does have some extensions built in. Most of apple's extensions are concerned with either making the GUI work more like native Mac apps (like com.apple.eawt and com.apple.laf) or interfacing with QuickTime (quicktime.*) – Gavin S. Yancey Nov 06 '13 at 02:55
  • How to do this for gradle? dependency to 'com.apple:AppleJavaExtensions:1.4' does not seem to work – Jochen Nov 20 '15 at 16:38
  • I found out: for gradle add this dependency: compile fileTree(dir: '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes', include: 'ui.jar') – Jochen Nov 20 '15 at 17:06