SystemTray icon indicating copy to clipboard operation
SystemTray copied to clipboard

compile error: no such class: sun.lwawt.macosx.event.NSEvent

Open bdw429s opened this issue 4 years ago • 29 comments

Getting this error on OpenJDK 11

[ERROR] dorkbox.systemTray.SystemTray: Error changing SystemTray mouse trigger for MacOSX.
javassist.CannotCompileException: [source error] no such class: sun.lwawt.macosx.event.NSEvent
        at javassist.CtBehavior.setBody(CtBehavior.java:474)
        at javassist.CtBehavior.setBody(CtBehavior.java:440)
        at dorkbox.systemTray.util.SystemTrayFixes.fixMacOS(SystemTrayFixes.java:307)
        at dorkbox.systemTray.SystemTray.init(SystemTray.java:1030)
        at dorkbox.systemTray.SystemTray.get(SystemTray.java:1167)
        at runwar.tray.Tray.hookTray(Tray.java:67)
        at runwar.Server.startServer(Server.java:686)
        at runwar.Start.main(Start.java:124)
Caused by: compile error: no such class: sun.lwawt.macosx.event.NSEvent
        at javassist.compiler.MemberResolver.searchImports(MemberResolver.java:479)
        at javassist.compiler.MemberResolver.lookupClass(MemberResolver.java:422)
        at javassist.compiler.MemberResolver.lookupClassByJvmName(MemberResolver.java:329)
        at javassist.compiler.MemberResolver.resolveJvmClassName(MemberResolver.java:519)
        at javassist.compiler.MemberCodeGen.resolveClassName(MemberCodeGen.java:1190)
        at javassist.compiler.CodeGen.atDeclarator(CodeGen.java:757)
        at javassist.compiler.ast.Declarator.accept(Declarator.java:103)
        at javassist.compiler.CodeGen.atStmnt(CodeGen.java:381)
        at javassist.compiler.ast.Stmnt.accept(Stmnt.java:53)
        at javassist.compiler.CodeGen.atStmnt(CodeGen.java:381)
        at javassist.compiler.ast.Stmnt.accept(Stmnt.java:53)
        at javassist.compiler.CodeGen.atMethodBody(CodeGen.java:321)
        at javassist.compiler.Javac.compileBody(Javac.java:228)
        at javassist.CtBehavior.setBody(CtBehavior.java:466)
        ... 7 more

bdw429s avatar Mar 12 '20 22:03 bdw429s

This library is not JDK11 compliant.

The reason is that SystemTray uses some Java internal classes (Such as things in sun.*) which is no longer allowed with the new module system.

I don't know this could be updated except by re-creating what's missing (Thus probably a lot of C/C++ bindings). I had this issue when I tried to implement Windows' Vibrancy-like feature, getting HWND was possible through sun.* but we can no longer use it so we need to resort to JNI/JNA

oxodao avatar Sep 03 '20 12:09 oxodao

Sadly, that's correct -- It doesn't work with JPMS yet. I'm working on a solution for it.

dorkbox avatar Sep 03 '20 18:09 dorkbox

@dorkbox Thanks for the effort, this library is a big part of my CLI tool that thousands of people use every day and the tray integration is very nice. I appreciate the library and look forward to hopefully finding some workarounds on openjdk in the future :smiley:

bdw429s avatar Sep 03 '20 18:09 bdw429s

You're v. welcome! I'm glad others find it useful.

I'll be making a JDK11+ version (and bump the major version, so if you use java 8, then you just use the old one) -- that has a lot less magic in it. It's.... tricky to get it working the way one expects in a cross-platform manner.

dorkbox avatar Sep 10 '20 17:09 dorkbox

@dorkbox Sounds great. My users use all manner of JRE versions from 8 and up. Will the new version be compatible with 8 still? Just checking, since I only have one version of my Java-based CLI tool that simply supports 8+.

bdw429s avatar Sep 10 '20 23:09 bdw429s

Hm. I might be able to just check for 9+, and disable things if so -- this way your library can stay 8+

dorkbox avatar Sep 11 '20 08:09 dorkbox

That would be fantastic if you could get it to fall back nicely. Unfortunately, a lot of CFML developers have been slow to move off of JRE 8 or they are still using older versions of their app server that requires it. I'll probably have to keep supporting it for a few more years :/

bdw429s avatar Sep 11 '20 16:09 bdw429s

What is the status on the JDK11 version?

I am getting This operation is permitted on the event thread only; currentThread = GTK Native Event Loop when calling Tornadofx from SystemTray.

When I try suggested solution it says Toolkit not initialized which, if I am understands correctly, are due to some mismatching in java versions

Edit: The suggested solution was to wrap in a runlater runLater { launch<TornadofxApp>() }

NangiDev avatar Oct 08 '20 13:10 NangiDev

Just a heads up, I've started working on this project again.

dorkbox avatar Oct 08 '20 23:10 dorkbox

I found this thread on forcing javafx/tornadofx into GTK 3

https://stackoverflow.com/a/22457177/3021593

Now I just need to figure out how to call the tornadofx launch method from systemtray thread or based on Not on FX application thread; currentThread = GTK Native Event Loop I guess I need to figure out how to switch to FX thread

NangiDev avatar Oct 10 '20 16:10 NangiDev

Java11 + macos is now working.

Thanks for the bug report!

dorkbox avatar Mar 30 '21 22:03 dorkbox

WUT? Awesome!!! Looking forward to the release

bdw429s avatar Mar 31 '21 01:03 bdw429s

@dorkbox Is this available in a new release yet?

bdw429s avatar Sep 24 '21 20:09 bdw429s

Sadly, not yet. I've been stuck in the middle of some 2 major back-to-back releases, and haven't had much time for, quite literally, anything.

This is still the top prio for fixes though, so a release will arrive as soon as the dust from everything else settles.

dorkbox avatar Sep 24 '21 21:09 dorkbox

@dorkbox Thanks for the update and let us know if there is anything we can do to help you.

bdw429s avatar Sep 24 '21 21:09 bdw429s

@dorkbox I see the 4,.0 milestone was marked complete last week, but I don't see a 4.0 tag. Is the release available anywhere yet or are you still cooking it?

bdw429s avatar Dec 20 '21 17:12 bdw429s

Still working on it. (of note, I just fixed some JPMS (and build) dependency issues. so there is progress going forwards on this)

dorkbox avatar Dec 20 '21 17:12 dorkbox

@dorkbox Is there any bleeding edge builds we can use of 4.0 to test this? I've been pushing back on my Mac users for a very long time now. Even if I can use a snapshot version with the fix, that would be great.

bdw429s avatar Feb 08 '22 16:02 bdw429s

Sadly, no bleeding edge versions that work yet. I’ll see about getting a intermediate release done (still not fully supporting JPMS, but at least there will be fixes for these issues).

dorkbox avatar Feb 09 '22 08:02 dorkbox

Thank you, I'm getting pressure to drop this lib due to this issue, so I would love an intermediate release I can test.

bdw429s avatar Feb 09 '22 14:02 bdw429s

Thank you, I'm getting pressure to drop this lib due to this issue, so I would love an intermediate release I can test.

Well to be honest, unless you are willing to build it yourself, that's pretty much the only lib that will do the job.

Not only in Java but pretty much in all languages (without going full C++ or something like that). There is the vanilla libappindicator but there is no documentation / example for python, and the systray library from getlantern in Golang but it misses some things (No way to remove an item from the menu ???) but that's pretty much it... Or at least that I could find.

Vanilla java systray could do the job but those are based on AWT so they are ugly as hell anyway

I'm on my way to build a systray-based app but it's on hold until I can use this lib properly or find something that would do the job...

oxodao avatar Feb 09 '22 23:02 oxodao

@dorkbox Can we get a fix on this please. I am willing to sponsor this feature and give you either a $250 Amazon gift card or direct cash transfer for your time on this. Will this be of interest to you.

lmajano avatar Mar 24 '22 20:03 lmajano

Can we get a fix on this please? My company uses commandbox which relies on this library. Now we get some failues on the new MacBooks with M1 processor.

bferdinandus avatar Mar 25 '22 11:03 bferdinandus

Yes! I’m wokring on it directly! I just recently got an M1, so i’m able to do direct development on it.

dorkbox avatar Mar 25 '22 15:03 dorkbox

@lmajano I appreciate the offer, and money is nice, but not necessasry :)

dorkbox avatar Mar 25 '22 15:03 dorkbox

That’s great 😀!! Anyways we know first hand how hard it is to do open source and most of the time our work is not seen. I just want to let you know that we appreciate your work on this library and we are willing to remunerate and recognize.

We value your work and dedication.

lmajano avatar Mar 25 '22 16:03 lmajano

Three months later. Any update?

onlyleura avatar Jun 20 '22 21:06 onlyleura

@dorkbox We are super excited that this is so close to being resolved, do you have an idea when it will be ready to launch?

scottsteinbeck avatar Jun 20 '22 21:06 scottsteinbeck

At the moment, I’m blocked by https://github.com/dorkbox/SystemTray/issues/172#issuecomment-1104865978

dorkbox avatar Jun 21 '22 19:06 dorkbox

Sorry this took so long, but it was not easy. I have figured out what exactly is going on, and how to work-around it. macos11 (Big Sur) changed how to create UI elements.

dorkbox avatar Dec 26 '22 00:12 dorkbox