Packaging a Module - Java Object Oriented Design

Java examples for Object Oriented Design:Module

Introduction

Utilize the jar utility to package modules and to make executable modules.

To package a module, navigate to the directory which contains the module and src directories.

From within that directory, execute the following commands via the command line:

mkdir lib 
jar --create --file=lib/org.firstModule@1.0.jar --module-version=1.0 --main-class=org.firstModule.Main -C mods/org.firstModule . 

This utility will package the module into a JAR file within the lib directory.

The JAR file can then be executed with the java executable as follows:

java -p lib -m org.firstModule 

The jar utility has been enhanced for Java 9 to include a number of new options.

The following table lists the options of the jar utility.

jar Utility Options

Option Description
-c, --createCreate an archive
-I, --generate-index=FILE Generate index information for specified jar files
-t, --list List an archive's table of contents
-u, --updateUpdate an existing jar file
-x, --extract Extract one or more files from a jar file
-C DIR Change to the directory that is specified and include file
-f, --file=FILE Name of the jar file
-v, --verbose Generate verbose output
-e, --main-class=NAME The main class or entry point for a module that will be packaged into the jar
-m, --manifest=FILE Include specified manifest file information with the jar
-M, --no-manifest Omit manifest
--module-version=VERSIONModule version
--hash-modules=PATTERN Compute and record hashes of modules matched by the specified pattern
-P, --module-path Location of module dependency for generation of hash
-0, --no-compress Specifies that no ZIP compression shall be used

Related Tutorials