JAVA SWT/AWT Eclipse Mac OSX Java Cocoa CompatibilityMode Enabled
Asked Answered
I

3

14

I'm developing a fairly complex Java application mixing Swing and SWT. Whenever I start the application, this is the console output (and the app doesn't show up):

2012-12-19 12:45:45.359 java[3442:f07] [Java CocoaComponent compatibility mode]: Enabled
2012-12-19 12:45:45.360 java[3442:f07] [Java CocoaComponent compatibility mode]: Setting timeout for SWT to 0.100000

I've followed many guides and tutorials setting:

  1. System.setProperty("com.apple.awt.CocoaComponent.CompatibilityMode", "false");
  2. -XstartOnSecondThread
  3. --launcher-on-secondThread

Now I really don't have any clue. The only way to make my app working on Mac OSX is to export the Eclipse project to a JAR executable. Well, this is annoying. Can someone explain to me how to set those properties above? Are there any magic trick?

EDIT: I'm using:

OSX Mountain Lion 10.8.2 ,
Java 1.6u37 64bit,
SWT 4.2 cocoa x64,
Windows XP ,
Java 1.6u37 32bit,
SWT 4.2 32bit 
Inamorato answered 19/12, 2012 at 11:53 Comment(10)
What version of Eclipse?Raybourne
Now i'm downloading Indigo ... hope this will solve the problemInamorato
Nope, it's not working with Indigo tooInamorato
You're saying that you're not setting those properties when you run from Eclipse? If you are setting them, how?Seventieth
Edward, I set CompatibilityMode false like above (first line of code), I added --launcher.secondThread to eclipse.ini just before -vmargs , and tried -XstartOnSecondThread on Run as -> Configurations -> arguments ... I tried also -XstartOnFirstThread with no success. On Windows XP with Java 1.6u37 32bit and SWT 32bit is running well. Here I have OSX Mountain Lion with Eclipse Indigo cocoa x64 and SWT x64.Inamorato
It would seem likely that you'll need to set this in your Run/Debug Configuration after -vmargs, setting this in eclipse.ini should have no effect. I would think you would simply want -vmargs -Dcom.apple.awt.CocoaComponent.CompatibilityMode=false -XstartOnFirstThread. You should not need --launcher.secondThread as that only affects the Swing launcher. To my knowledge, there is no such thing as -XstartOnSecondThread.Seventieth
Well, maybe is because of my flu but I'm a bit confused. In ’eclipse.ini’ I '-Dcom.apple.awt.CocoaComponent.CompatibilityMode=false -XstartOnFirstThread' right after '-vmargs'. That's all? Or do I need to set something else in 'Run configurations -> Arguments -> VM Arguments/Program arguments'? Thanks BTWInamorato
well, I put "...CompatibilityMode=false" and "-XstartOnFirstThread" under "Run configurations -> Arguments -> Program arguments" but still not workingInamorato
Have you seen this question? https://mcmap.net/q/902629/-gwt-osx-swt-issuesFacula
Yep, no help though ... thinking about JavaFX (but no Flash! :-( )Inamorato
P
1

I've had this issue several times, as I work in a Java shop where everyone uses Eclipse, and I'm an OS X user.

The fix is a little weird.

You need to remove your current JRE from the "Installed JREs" preference, and then add it again. When you do so, make sure that you select "Standard JVM" and not "Mac OS X JVM".

Adding JREs is a little annoying, so take note of the "Location" path string before you do so. You'll point it to the same place, just change the "Type" property.

So, my answer is wrong. It's pertinent if you're doing Swing/AWT only, but humorously enough immediately after posting this I had to write an SWT_AWT boondoggle and I got the same error on my Mac, even with the above settings. I suspect that it has to do with the differences between Swing/AWT and SWT regarding the event loop (SWT = bring your own, Swing = provided by JVM). I also get the error in IntelliJ IDEA 12, so it can't just be an Eclipse issue.

Penna answered 20/2, 2013 at 16:22 Comment(3)
I ended up using Netbeans which starts correctly the first time without adding anything. It's such a shame that a so called "multiplatform" language has so many problems when switching around from PC to Mac to GNU/Linux. :-(Inamorato
@Inamorato Agreed, but SWT != Java. Java does a pretty good job of being cross-platform by itself, but SWT is highly dependent on native code and the quality of the bridge to it. It's also not part of any official Java working spec, it's owned by the Eclipse foundation and was originally an IBM product. Anything that relies on native libraries is going to be painful to deploy cross-platform.Penna
Yep that's true, I'm thinking about porting to JavaFX. Doing so I can delete all of the Swing and SWT pieces. JavaFX has his own implementation of a webbrowser.Inamorato
N
0

I had the same problem in my Macbook, as I can see you're downloading the Eclipse Indigo, which is the best you can do. Juno has bugs and also is slow since it consumes more performance than previous releases. I think Indigo is the best option. I know Java is portable and multi-platform but after being working with apple devices I found some kind of incompatibilities with Java, I think not because of Java, but because of the iOS, that's why for me the best I could do was to install a virtual machine with Ubuntu. So you can try the same with the Linux distribution you prefer.

Nicolenicolea answered 20/2, 2013 at 12:55 Comment(0)
N
0

i had a simular problem when i used a jar for generating graphs. je jar used swt which seem to be not compatible with OSX. If you have are using swt or have imported a jar using swt try deleting it and fiding an equivalent that uses awt

Neom answered 14/2, 2015 at 0:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.