I am pretty sure that almost every Java developer knows that MANIFEST.MF can have a CLASS-PATH entry. If they are making executable jars they would have to know that.
I worked many years with Swing so that is probably why I know about it. For desktop apps it is needed so a user can just double-click on a jar file to fire up an app. But now since I think about it someone that has never wrote desktop apps with Java would have no reason to know about it.
All OSs support it. However, you need the JRE installed which doesn't exist in Java 11 and later so it will only work with Java 10 or earlier. These days the preferred mechanism is bundling a runtime with your app with jlink/jpackage.
My Swing development work was prior to Java 11. I no longer do it.
Just tried on Linux and Mac and as I expected, they block running it. Like I said, it used to work long time ago ( I also used to distribute Swing apps like that, good times ) but it doesn't anymore for many years as far as I know.
Listen, I know how to do this. All I am saying is that it won't work for anyone on any OS out-of-the-box, except if explicitly disable the OS's security mechanisms (which I wouldn't advise anyone should do except for programmers who can actually read the code) no matter what you do, and if you think you can notarize and run a jar I'm sorry but you're dreaming. Have you ever seen anyone doing this in the last 10 years?
Oh here is another fun one for you. You can put any attributes you want in a MANIFEST.MF.
So you can use it instead of loading some sort of custom properties file from the classpath.
That is instead of doing classpath:/application.properties and loading that up you can just load up the MANIFEST using JDK java.util.jar.Manifest.
So let us say you have custom meta/config data that is populated at build time you can have Maven store in the MANIFEST.MF.
Why would you do that? Well for one I think it is automatically graalvm friendly and two it avoids yet another resource load call (loading shit up from the classpath has surprising cost at times) since I think the MANIFEST.MF is always loaded (well at least the main jar it is).
Well I know you would for sure (and probably many of the top commenters here) but I have worked with lots of offshore teams. Most just rely on whatever Spring Boot does which does not do that btw.
See most rely on Spring Boots mechanisms or they use the Shade plugin.
For example show me a tutorial on the web that shows how to make an executable jar with what I recommend. Most are Maven Shade or Spring Boot (or whatever the framework provides).
I actually didn't, it just never came up. The systemd service takes care of specifying the class path for me, and I do not configure maven to make fat jar. It makes sense though... I could learn more about maven but someone else on the team takes care of that.
View all comments
Show parent comment
4
u/wildjokers Jan 02 '25
I am pretty sure that almost every Java developer knows that MANIFEST.MF can have a CLASS-PATH entry. If they are making executable jars they would have to know that.