So, Java is rich on surpises, one can find some funny features in some pretty boring places. For instance, as boring as jar files.
Let's say, I 've got a jar which I run as usual:
Then, if my program does something useful than it probably make use of some third-party libraries. And since I don't feel happy about annoying my users, I'd like to ship that libraries together with my application. Most common aproach is to use so-called "uber-jar" which contains third-party jars compiled into it. There is a maven plugin that can do so (sure, there is!), it installs it's own MainClass that installs it's own classloader and than yields for my MainClass. That classloader can load classes from jars inside the jar and is pretty much like one can find in the java tutorial from oracle.com.
While uber-jar is very convinient way for deploying an application, there are useful and important proprietary third-party libraries which have licences that don't allow me to bundle them inside my jar. And since one does not simply run java with both -jar and -cp options, I need a better solution. And there it is. I'd even say, sure there they are.
Let's say, I 've got a jar which I run as usual:
java -jar my-fancy-app.jar
For this to work I need to add MainClass into manifest file, there is nothing to see there, except that jar files like this are called "executable" for some strange reason.Then, if my program does something useful than it probably make use of some third-party libraries. And since I don't feel happy about annoying my users, I'd like to ship that libraries together with my application. Most common aproach is to use so-called "uber-jar" which contains third-party jars compiled into it. There is a maven plugin that can do so (sure, there is!), it installs it's own MainClass that installs it's own classloader and than yields for my MainClass. That classloader can load classes from jars inside the jar and is pretty much like one can find in the java tutorial from oracle.com.
While uber-jar is very convinient way for deploying an application, there are useful and important proprietary third-party libraries which have licences that don't allow me to bundle them inside my jar. And since one does not simply run java with both -jar and -cp options, I need a better solution. And there it is. I'd even say, sure there they are.