19.13 Exploring Modules
This section provides an introduction to using the JDK tools to discover, explore, and analyze modular applications.
Given the JARs main.jar, control.jar, view.jar, and model.jar for the adviceApp application in the mlib directory in Figure 19.14(c), p. 1188, we will use JDK tools to explore these archives for miscellaneous information about this application.
Listing the Contents of a JAR
We can list the contents of a JAR using the –list option (short form: -t) of the jar tool. The JAR file is specified with the –file option (short form: -f). The contents of main.jar are printed by the following jar command:
>jar –list –file mlib/main.jar
META-INF/
META-INF/MANIFEST.MF
module-info.class
com/
com/passion/
com/passion/main/
com/passion/main/Main.class
From the output on the terminal, we can see that there is a META-INF directory listed, in addition to the module descriptor file (module-info.class), the directory hierarchy of the package com.passion.main, and the file Main.class contained in it.
The META-INF directory is used internally to record any metadata in the JAR archive. In the listing above, the META-INF directory contains the file MANIFEST.MF. This manifest file is used to store any necessary information (specified as attribute-value pairs)—for example, the Main-Class attribute to designate the entry point of the application.
Extracting the Contents of a JAR
The jar tool can be used to extract the contents of a JAR into a desired directory. We illustrate the extract operation on main.jar. The following commands create the main-extracted directory under the current directory and change the working directory to it, respectively.
>
mkdir main-extracted
>
cd main-extracted
The jar command below with the –extract option (short form: -x) will extract the contents of main.jar into the main-extracted directory, which is now the current working directory. The structure of the main-extracted directory is also shown below after the extraction (printed using the tree command), showing the exploded module structure and the META-INF directory from main.jar.
>jar –extract –file ../mlib/main.jar
>tree -F –dirsfirst –noreport main-extracted
main-extracted
├── META-INF/
│ └── MANIFEST.MF
├── com/
│ └── passion/
│ └── main/
│ └── Main.class
└── module-info.class
The contents of the MANIFEST.MF file, listed below using the more command, show that the entry point of the application is given by the value of Main-Class—that is, the class com.passion.main.Main.
>
more main-extracted/META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 17.0.2 (Oracle Corporation)
Main-Class: com.passion.main.Main
Leave a Reply