jar_Archive operation_Note_20200811

jar-Archive operation

** Prior basic knowledge **

・ What is an archive?

A collection of multiple files and folders into a single file

** 1. What is the jar command **

A Windows executable is usually a single file with an exe extension. On the other hand, an executable program developed in Java is a collection of multiple class files (.class).

In this way, in the format of "a set of multiple class files", There is also the possibility of accidents such as missing files when passing them to another developer. At the development site, the author also asked me to actually divide the class files into small pieces.

Therefore, as an archive format (see the basic knowledge in advance) that puts those files together into one, ** JAR (Java Archive) ** is defined.

If you use the jar command that comes standard with the JDK, you can create multiple class files, property files, etc. Collectively make one JAR file, or conversely expand the contents of the JAR file to the original class file etc. I can do it. (Fig. 1)

** Figure 1 ** コメント 2020-08-11 114326.png

** 1. Basic usage of jar command **

What you normally do with the jar command "Create archive", "Expand archive", and "View archive contents". Execute each with the following command

**-Create archive **

jar -cvf JAR file name File and folder ...

**-Expanding the archive **

jar -xvf JAR file name

** ・ Viewing archive contents **

jar -tvf JAR file name

For example, if you want to create Test.jar by combining Test1.class and Test2.class, execute the following command.

>jar -cvf Test.jar Test1.class Test2.class

** 2. Manifest file **

Of course, you've probably used archived compressed files such as zip and lha. In fact, the JAR format is almost the same as the zip format. (If you rewrite the extension of the JAR file to zip, you can unzip it with software that unzips the zip file without any problem.)

However, the JAR file contains additional information about the various files contained in the archive. It is common to include a ** manifest file **.

The manifest is in text file format and is in the META-INF folder in the archive. It is a rule to store it under the name MANIFEST.MF.

** 3. Benefits of using JAR files **

-Efficient file area

Compressing reduces the file space required and increases efficiency

·Security

JAR files can be signed, which can ease some security restrictions.

If you have any wrong knowledge, I would appreciate it if you could teach me.

Recommended Posts

jar_Archive operation_Note_20200811