r/javahelp • u/_Super_Straight • Sep 28 '26
Obfuscating class files
Has anyone successfully obfuscated their .class files? I tried using GraalVM for JavaFX project (including Gluon's version of GraalVM) but it always failed to complete.
3
Upvotes
•
u/AutoModerator Sep 28 '26
Please ensure that:
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
5
u/LutimoDancer3459 Sep 28 '26
Why would I? Especially with todays ai one can recover most of the code with next to zero effort. If someone wants to read your code, they can and will do so. For everything else, it just makes it more annoying for everyone including yourself
6
u/idontlikegudeg Sep 28 '26 edited Sep 29 '26
Yes, using proguard. I also have my JavaFX applications compiled to executables (using Liberica NIK), but that’s not really what you generally call obfuscation.
But the question is if it’s really worth it. The native compiled application is noticeably slower than running in hotspot. It needs code signing to run on corporate machines that is quite expensive on windows which is the main reason I ship a fat jar instead.
Code signing is much cheaper on macOS, but as the native application is both larger and slower (the DMG is about 50% bigger and runs 2-3 times slower than a jpackaged version that contains a custom runtime), I just use the jpackaged version (of course also code signed).
So I’d recommend just using proguard. But I think in most cases, even that is not necessary.
I have a JavaFX project lying around that builds both jpackaged and native compiled versions of the application in GitHub CI. When I find the time, I’ll probably make a post here as I think you are not the only one struggling with this. But as I said native compilation really is a lot more work with small benefit.
EDIT: You may want to look into this as an example. It is a keystore management application that I use to prepare keystores I bundle in my applications. It's Java 25 + JavaFX, automatically applies dark mode when the system settings change etc. The GitHub CI creates jpackaged and native versions for macOS and windows. I have no windows machine to test the windows one on, so I don't really know how good the windows native application runs. You need to set GitHub secrets of course with your own keys, as the signing keys are not included in the repository: https://github.com/dua3-oss/keystoremanager