Skip to main content

Breaking Module Encapsulation

  • Chapter
  • First Online:
Java 9 Revealed
  • 1457 Accesses

Abstract

One of the main goals of JDK 9 is to encapsulate types and resources in modules and export only those packages whose public types are intended to be accessed by other modules. Sometimes, you may need to break the encapsulation specified by a module to enable white-box testing or use unsupported JDK-internal APIs or libraries. This is possible by using non-standard command-line options at compile-time and runtime. Another reason for having these options is backward compatibility. Not all existing applications will be fully migrated to JDK 9 and will be modularized. If those applications need to use the JDK APIs or APIs provided by libraries that used to be public, but have been encapsulated in JDK 9, those applications have a way to keep working. A few of these options have corresponding attributes that can be added to the MANIFEST.MF file of the executable JARs to avoid using the command-line options.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Institutional subscriptions

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Kishori Sharan 2017, corrected publication 2018

About this chapter

Cite this chapter

Sharan, K. (2017). Breaking Module Encapsulation. In: Java 9 Revealed. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-2592-9_9

Download citation

Publish with us

Policies and ethics