
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How can we modify an existing module in Java 9?
The module is a named, self-describing collection of code and data. The code has been organized as a set of packages containing types like Java classes and interfaces. The data includes resources and other kinds of static information. We need to declare a module then add module-info.java at the root of the source code.
Below is the template of the "module-info.java" file.
module <module-name> { requires <module-name1> ; requires <module-name2>; exports <package-name1>; exports <package-name2>; exports <package-name> to <module-name> }
We can use certain command-line options that help us to modify existing modules and add dependencies to them, export additional packages.
Below are the few command-line commands that can be used to modify an existing module.
1) --add-reads <module>=<target-module>(,<target-module>)*
The above command can update <module> to read < target-module>, regardless of the module declaration. <target-module> can be ALL-UNNAMED to read all nameless modules.
2) --add-exports <module>/<package>=<target-module>(,<target-module>)*
The above command can update <module> to export <package> to <target-module>, regardless of the module declaration. <target-module> can be ALL-UNNAMED to export to all nameless modules.
3) --add-opens <module>/<package>=<target-module>(,<target-module>)*
The above command update <module> to open <package> to <target-module>, regardless of the module declaration.
4) --patch-module <module>=<file>(;<file>)*
The above command can replace or increase a module with classes and resources in jar files or directories.
- Related Articles
- How can we modify an existing MySQL event?
- How can we display all module names in Java 9?
- How can I modify an existing MySQL column’s data type?
- How can I modify an existing column's data type?
- How can we create an unmodifiable Set in Java 9?
- How can we create an unmodifiable List in Java 9?
- How can we update an existing JSON data using javax.json API in Java?
- How can we RENAME an existing MySQL event?
- How can we create an unmodifiable Map in Java 9?\n
- How can we create an instance of VarHandle in Java 9?
- What is an unnamed module in Java 9?
- How can we delete an existing MySQL event permanently?
- How can we drop an existing database by using mysqladmin?
- How can we get an ID of the running process in Java 9?
- Can we use private methods in an interface in Java 9?
