Tips for building Java applications on Windows
( 4 min read )
Are you developing a Java AWT/Swing application?
Is your target audience--or entire company--using Windows?
Well, you're not alone. There are a lot of Java developers who end up writing applications for their Windows coworkers (ahem, like me!). Its strange to be programming in a language meant to be run on all operating systems, yet somehow, gets only used on one OS.
So what's the problem then?
There isn't a problem, per se. But the default no-frills use of a Java application on a Windows operating system is boring.
You won't be impressing your audience with your Java skills very much if they have to open the command line and run "
java -jar \\path\\to\\jar\\application.jar -Xmx 512m" every time they want to use your application.
It would be safe to say, most java desktop applications, typically use the AWT/Swing libraries, and are typically packaged as a Runnable-JAR file or "
.jar". This is not what many Windows users are used to: "
.exe" or executable file. Then there is the process name in Task Manager, that shows up as the very unintuitive, "
javaw.exe". Not to mention there is not installation or uninstalltion that Windows users have grown to expect. They don't rely on a package manager like yum or rpm. And your application wouldn't be listed in the "Program -> Uninstall a program" list. And of course, the default icon for your Java program is the Java coffee cup logo, which honestly gives an old 1990's vibe.
How do I tweak my Java app for Windows?
We can fancy it up with these changes:
- Set a nice "
.ico" icon for the app (Create one and then set it using this code.)
- Wrap the JAR in an EXE (Launch4J)
- Create an Install Wizard (Install4J)
- Set desktop and start menu shortcuts (VBS scripts)
- Add the application to the Programs List via a Registry entry (You can use this code.)
- Rename "
javaw.exe" to "
your-application.exe" by bundling a JVM runtime with your app (Launch4J or JSmooth)
These tweaks to your java application will make it snazzy and feel right at home for your Windows users. Feel free to implement as many as you can to your application. You'll be sure to impress your non-power users AND still deliver the same, awesome, superb code you've been writing all this time.
Keep in mind, these changes are for Windows users only and wouldn't work at all on other operating systems, like Mac or Linux. So don't forget to keep a separate package/installer for your other users. Java is ideally, platform independent, but that doesn't mean we can't enhance our applications for each platform.
Also, I may cover each of these tweaks in further detail, in the future. For now its just important to detail what these are and point out how they can be accomplished. Let me know if I missed any or if you have suggestions to add!
Published: Sep 29, 2016