I'm trying to find a way to build an archive that will contain an executable jar for a Java application (Spring Boot), along with supporting artifacts such as a script to launch the jar and possibly other related resources. BTW, I'm using Maven for the build process.
I'm not overly familiar with what makes an executable jar "executable", nor what such a jar may actually contain, or how it's "used" by the Java runtime. What I mean by this is that it seems that supporting resources (config files, etc.) are somehow bundled inside the jar and yet, when executed these resources are "seen" by the jar/runtime.
A quick search reveals a number of methods to create an executable jar, and I have tried a couple techniques. A good example on the subject is here: https://www.baeldung.com/executable-jar-with-maven.
While they produce a jar that's executable, I can't figure out how to also package the jar up with a script and/or other resources.
These are the methods I've tried (so far):
spring-boot-maven-plugin:
Since my application is written as a Spring Boot app, it made sense to use this plugin. The
repackage
goal can be used to "repackage" the jar as an executable jar. Wonderful (and it works great). But that's all this plugin does. It does not appear to provide the capability to create a package bundling supporting script/resource files.I can use my launch script to run the jar and pass whatever arguments it needs. However, I need to package the script and the jar together and I don't think this plugin can do that.
maven-assembly-plugin:
Before experimenting with making an executable jar, I used the assembly plugin to create an archive (zip) that contained a "plain" jar of the app, a
lib
directory with all dependencies, plus supporting artifacts: launch script, configuration files, etc.The plugin also has the capability to create an executable jar by defining an
<archive>
in the plugin configuration. I experimented with this and it does create a jar that appears to bundle the app jar, the dependencies and it also copied in most (but not all) of the related artifacts that I specified in the assembly.xml. They were placed inBOOT-INF/classes
directory. Oddly, It did not copy in the launch script. The thing is, even if it had copied the script, how would I use it? It's buried inside the jar file!I can't figure out if there is a way to include the executable jar in the zip to replace the "plain" jar and the
lib
directory.
After these two attempts I thought that maybe I could use the spring boot plugin to produce the executable jar and then just have the assembly plugin package it up with the support files. This does not work, however, because the assembly plugin is called before the spring boot plugin in the maven build order.
Any ideas? Suggestions?