Packaging Java JARs as RPM packages
At JUDCon 2012, I had a discussion and argument with Jaikiran Pai and Ravi Maurya on “Packaging Java JARs as RPM packages”.
Well it is not just RPM, it could be any package management system ( eg. dpkg, protage etc. ), doesn’t matter as long as it serves the purpose of:
- automatic dependency resolution
- installation of dependencies
- rollback an install step
- install multiple versions of a (JAR) package
- ensure the packages are authentic ( for security )
How is all this achieved in Java world? Simple. Just package all the required JARs in a single JAR or WAR or an EAR for that matter. And trust the packager for its security. But:
- Is this a good practice?
- What happens when you want to install the same package on multiple systems?
- Can you roll back changes easily on multiple installations?
- How are JARs shared across different kind of projects, some which use the same version of the same JAR package?
Consider the case of Maven, with which you can easily specify the dependencies and Maven does all the work of dependency resolution.
However, it solves the problem only at the developer’s level. JARs are still bundled inside the output application package (JAR / WAR / EAR). And everytime this application is distributed, it will contain “ALL” the dependencies. That is clearly an overhead.
That makes me think, why JARs don’t work like Shared Libraries, which can be shared across applications. Every classloader / JVM instance has its own version of the same JAR file on-disk! Can’t they be shared? That too is clearly an overhead. I am not aware of the reasons why it is so, which I would definitely like to know.
The point is, since a package manager has all the functionality, why not just leverage it? Java community is either unaware of it, or doesn’t care.
No problem. There are efforts already in place.
Anyway, of other things Jaikiran told me that, JBoss AS7 has how better and modular class loading which is based on JBoss Modules. This appears to me similar to how Maven structures it JAR repositories.
Here are some resources:
- What is the proper way to package a single jar file as rpm?
- Packaging Java Apps for Ubuntu @ FOSS.IN
- Java Packaging in Fedora
- Creating an RPM for a Java Application
- Maven plugin to create RPM packages
Thats it folks!
Matěj Cepl 12:14 pm on January 27, 2012 Permalink |
Would it be possible to create Project Jigsaw packages with some external tools even before the arrival of Java 8?
tuxdna 12:51 pm on January 27, 2012 Permalink |
I am not aware of Project Jigsaw, so maybe if I read about it more I can tell better.
http://openjdk.java.net/projects/jigsaw/
However I got some pointer which might help:
http://mail.openjdk.java.net/pipermail/jigsaw-dev/2011-June/001328.html
Thanks!
Chaitannya Mahatme 12:53 pm on January 27, 2012 Permalink |
Yup, I think the Java world doesn’t care, since they have a full-fledged packaging utility. I typically face this issue when working with Eclipse. We are working on debugger. So it’s like I would first launch 2 instance of eclipse, and then in the second instance I would launch another debugger. In this case JVM consumes 1 GB of Ram, otherwise which is normally in the range of 250-300 mb.
If you look at the plugins (jar packages) which I am using, 90-95% are the same ones. But in this case they have to be launched thrice.
Chaitannya Mahatme 12:56 pm on January 27, 2012 Permalink |
One more thing … I guess Java would lose it’s reputation of build once, run it everywhere if we have a packing system which is native to the OS.
tuxdna 12:58 pm on January 27, 2012 Permalink
Thats a good point. Therefore the packaging mechanism should be platform / OS agnostic.