Jar file attachments

question about creating jar executables. Suppose we have a jar file a.jar containing UI.class. I used the metafile in a.jar archiving that says

Main-Class: UI Class-Path: . b.jar c.jar 

Now, if I want to send this a.jar executable to someone, I have to send 3 files - a.jar, b.jar and c.jar. The user must put all 3 in the same folder, and then double-clicking on a.jar will work. It would be easier if I could send one file (a.jar), and the JVM could figure out how to extract b.jar and c.jar from it in order to use classes. These 2 are external libraries, and I do not want to expand them and re-place class files in a.jar.

Can this be done? If so, what is the jar command and what should be done in the metafile? Currently team

 jar cmf metafile a.jar UI.class 

Thanks.

+4
source share
5 answers

Have you viewed this OneJar tool? This is also a good article to read on OneJar.

If you decide not to use an external tool, then your alternative is to put the libraries / auxiliary banks in the class path in the manifest, and then copy the banks themselves into the directory path relative to your main bank.

EDIT: OP requested an example of MANIFEST.MF. I dealt with this from the example File with one bank jar file.

 Manifest-Version: 1.0 Main-Class: com.simontuffs.onejar.Boot One-Jar-Expand: expand,doc 
+1
source

There is OneJar, as people mentioned, but also (especially if you use eclipse), you can consider fatjar .

On the other hand, you can also achieve this using the ANT Task:

 <target name="dist" depends="compile,static" description="Compiles and builds jar files"> <mkdir dir="${dist}"/> <jar destfile="${dist}/MYAPP.jar"> <zipfileset src="${dist}/MY_OTHER_APP.jar"/> <zipfileset src="${lib}/commons-io-1.4/commons-io-1.4.jar"/> <zipfileset src="${lib}/commons-math-2.1/commons-math-2.1.jar"/> <fileset dir="${res}" includes="*"/> <manifest> <attribute name="Main-Class" value=<where your main class is>/> </manifest> </jar> </target> 
+1
source

OneJar is good for simply combining several things together, but it is usually quite slow and inflexible. It's not digging into OneJar, it's great for what it does, but if I didn't want to quickly and easily distribute for a tiny program, I would not use it.

I used it for a while, but then switched to izpack . It provides the installer as a single jar, which, it seemed to me, works very well, and supports features such as special shortcuts for Windows. It is also very easy to integrate it with ant.

0
source

Another way could be to use one of several available tools to create an installation, and your installation package will unzip your application during installation.

0
source

Maven users can also use the build plugin for this: http://maven.apache.org/plugins/maven-assembly-plugin/usage.html

0
source

Source: https://habr.com/ru/post/1337346/


All Articles