Reputation: 61
I am trying to build an installer for a couple of Java Maven projects (using Eclipse). I would like to use maven assembly to produce a jar file (henceforth big-fat jar) which contains all the installation files (JARs + docs + others) as well as the installer JAR (the result of building the installer project). I want the installer to unpack the big-fat jar and therefore I want the main class to be included in the installer jar. The user will get the big-fat jar and I want java -jar big-fat.jar to execute the main inside installer.jar. To recap, here is the structure of the big-fat jar:
big-fat-jar:
--installer.jar
--application.jar
--readme.doc,
--META-INF:
----MANIFEST.MF
where installer.jar is the Java program which unpacks big-fat-jar and contains main, application.jar is the application being installed (there may be multiple jars or wars instead of just one application.jar) and readme.doc stands for any docs. My question is: what do I do to make the main inside installer.jar be called when the user executes java -jar big-fat-jar? I read on other posts that OneJar may be helpful but I am not sure how to indicate that main resides inside the inner jar.
Upvotes: 0
Views: 582
Reputation: 1351
I have never tried this with a jar inside another jar as you have described but I think it could work if you specify this in your Manifest.txt
file. You could do this like so:
Manifest-Version: 1.0
Created-By: StackOverflow
Main-Class: installer.MyClass
In the example above the MyClass
file will have the main
method that will be called when running java -jar <jarname.jar>
Please see the top of this page for more information: https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html
Head First Java by Sierra and Bates also goes over how to do this with a class but not a Java jar inside another Java jar.
I hope this helps.
Thank-you for reading this.
Upvotes: 0