- Java 9:Building Robust Modular Applications
- Dr. Edward Lavieri Peter Verhas Jason Lee
- 298字
- 2025-04-04 17:08:34
Base module
When programming Java 9 applications, or porting existing applications programmed with older versions of Java, the base module (java.base) must be used. Every module requires the java.base module because it defines the critical, or foundational, Java platform APIs. Here are the contents of the java.base module:
module java.base
{
exports java.io;
exports java.lang;
exports java.lang.annotation;
exports java.lang.invoke;
exports java.lang.module;
exports java.lang.ref;
exports java.lang.reflect;
exports java.math;
exports java.net;
exports java.net.spi;
exports java.nio;
exports java.nio.channels;
exports java.nio.channels.spi;
exports java.nio.charset;
exports java.nio.charset.spi;
exports java.nio.file;
exports java.nio.file.attribute;
exports java.nio.file.spi;
exports java.security;
exports java.security.aci;
exports java.security.cert;
exports java.security.interfaces;
exports java.security.spec;
exports java.text;
exports java.text.spi;
exports java.time;
exports java.time.chrono;
exports java.time.format;
exports java.time.temporal;
exports java.time.zone;
exports java.util;
exports java.util.concurrent;
exports java.util.concurrent.atomic;
exports java.util.concurrent.locks;
exports java.util.function;
exports java.util.jar;
exports java.util.regex;
exports java.util.spi;
exports java.util.stream;
exports java.util.zip;
exports java.crypto;
exports java.crypto.interfaces;
exports java.crytpo.spec;
exports java.net;
exports java.net,ssi;
exports java.security.auth;
exports java.security.auth.callbak;
exports java.security.auth.login;
exports java.security.auth.spi;
exports java.security.auth.x500;
exports java.security.cert;
}
As you can see, the java.base module does not require any modules and it exports numerous packages. It can be useful to have a list of these exports handy so you know what is available to you as you start creating applications using the new Java platform, Java 9.
You will notice that in the previous section, we did not include the requires java.base; line of code in our declaration of our com.three19.irisScan module. The updated code is provided as follows and now includes the requires java.base; line of code:
module com.three19.irisScan
{
// modules that com.three19.irisScan depends upon
requires java.base; // optional inclusion
requires com.three19.irisCore;
requires com.three19.irisData;
// export packages for other modules that are dependent
upon com.three19.irisScan
exports com.three19.irisScan.biometric;
}
If you do not include the requires java.base; line of code in your module declarations, the Java Compiler will automatically include it.