59

After upgrading to OSX 10.8.4, background Java processes started placing a Java Cup icon in the Dock. It causes the currently active window to loose focus which is very annoying when running some script that forks many short running Java processes (headless). The file menu (top of the screen next to the apple symbol will show the name of the class file that Java is running, e.g. org.apache.hadoop.util.RunJar).

Since I'm not explicitly launching these Java commands, I've tried putting alias java="java -Djava.awt.headless=true" in .profile but this doesn't seem to help.

Has anyone run into this and know how to fix it?

Thank you.

maksimov
  • 5,792
  • 1
  • 30
  • 38
Eugene
  • 826
  • 1
  • 7
  • 7

4 Answers4

64

Like @EGHM said, it's -Dapple.awt.UIElement=true, but with no quotes. At least it works for me (OS X 10.7.5).

If you happen to be using Eclipse, you can add this JVM argument globally in Preferences → Installed JREs:

enter image description here

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
Nelson Menezes
  • 2,036
  • 14
  • 15
  • 9
    Thanks! I want to add that in OS X 10.10.4 it worked for me as well using: `System.setPropery("apple.awt.UIElement", "true");` as first statement in my `main()`. – Martijn Courteaux May 12 '15 at 08:12
  • This worked for me, but only for a few days :( The icon has now again started showing up in the dock. Any ideas? – Saket Jun 24 '16 at 07:18
  • ... and that happened on Mac OS 10.11.6 as well. Something triggered from gradle on an android project, needed `-Djava.awt.headless=true` alone didn't fix it all, `-Dapple.awt.UIElement=true` as well. – Filipe Esperandio Oct 20 '16 at 13:26
  • @FilipeEsperandio this seems to be gradle daemon process icon and has nothing in common with original question. https://code.google.com/p/android/issues/detail?id=201742 – Rawnald Gregory Erickson Jan 27 '17 at 22:50
17

Like @EHGM and @Nelson pointed out, -Dapple.awt.UIElement=true needs to be added as an argument to the JVM.

You can set it globally for all java applications launched from the command line (or a shell) by adding it to the JAVA_TOOL_OPTIONS environment variable.

export JAVA_TOOL_OPTIONS="-Dapple.awt.UIElement=true"

You could add the export statement to your $HOME/.bashrc or whatever startup script relevant to the shell you're using.

Tuxdude
  • 47,485
  • 15
  • 109
  • 110
9

Try -Dapple.awt.UIElement="true"

EGHM
  • 2,144
  • 23
  • 37
  • 2
    @Eugene Actually you noted -Djava.awt.headless=true I'm suggesting -Dapple.awt.UIElement="true" please note UIElement and quotes around true. – EGHM Jul 04 '13 at 20:42
6

You can also put the statement into the project-level or global gradle.properties file

systemProp.apple.awt.UIElement=true
xinthink
  • 1,460
  • 1
  • 18
  • 22
  • 老哥稳啊,太tm的感谢了! it works for me ! Android Studio 2.3.3 + macOS 10.12.5 – Loyea Jun 23 '17 at 06:32