hands on: java 16
we learned a lot of features in the latest episodes. in java 16 there aren't any new features for programmers. that's why the focus of this session will be outside the typical java environment. in this post let's have a look at the packaging tool. it was first introduced in java 14 and then finalized in java 16.
usually when developing a web app, it's the job of maven, gradle or any other build management tool to package the application. in the most cases a build pipeline does this job and deploys the application on a server in an isolated docker container with a java runtime environment. so in the common setting or configuration the jre is likely present.
sometimes you also want to build a small tool as a desktop application for users without knowledge or requirement of a technology stack. that's where the java packaging tools is very useful. in my personal experience, i've always exported a jar and provided it to the customers in the expectation that they already have or know how to install java on their machine.
thanks to jpackage, the end user needs only to download the to be installed file and start the installation. based on the environment you are working on the java packaging tool can create an installer for windows (msi, exe), macOS (pkg, dmg) or linux (rpm, deb).
here is a small example of how a packaging of your application might look like:
jpackage --name appname --input directoryname --main-jar archivename.jar --main-class appname.Main
you can specify a name, an input directory containing one or more jars, then the jar to be executed and the main class to be started. to see more options visit this https://openjdk.java.net/jeps/392.
since the trend shows that more and more applications are deployed in the cloud providing some web apps or services, this tool will be useless. but for people which write code for desktop applications, this tool can be very handy.
so what do you think about the changes? do you like it and will try to adapt them in upcoming process, or will you wait for the next lts before using it? let me know.