Just exploring new release of Java, its new module system, and playing with jshell as well. Probably my question doesn't have too much sense, but I am just curious.
So I came up with the question: Is there any way to create a module in jshell? Or module can be only created in module-info.java
?
The Java Shell tool (JShell) is an interactive tool for learning the Java programming language and prototyping Java code. It was introduced in JDK 9. JShell is a Read-Evaluate-Print Loop tool (REPL), which evaluates declarations, statements, and expressions as they are entered and immediately shows the results.
To start JShell, enter the jshell command on the command line. JDK 9 must be installed on your system. If your path doesn't include java-home/jdk-9/bin , start the tool from within that directory.
JShell is a new concept introduced in Java 9 version. It provides Java with REPL (Read-Eval-Print-Loop) ability. By using JShell, we can test the java-based logic and expressions without compiling it. REPL acts as an immediate feedback loop and has a great effect on productivity in that particular language.
Modules cannot be created using JShell currently and it is not a Goal of JShell either.
The JShell API will provide all of JShell's evaluation functionality. The code fragments that are input to the API are referred to as
"snippets"
. The jshell tool will also use the JShell completion API to determine when input is incomplete (and the user must be prompted for more), when it would be complete if a semicolon were added (in which case the tool will append the semicolon) and also how to complete input when completion is requested with a tab.
A snippet must correspond to one of the following JLS syntax productions:
A snippet
may not declare a package or a module. All JShell code is placed in a single package in an unnamed module. The name of the package is controlled by JShell.
In fact trying to use a ModuleDeclaration
within JShell is not a recognized syntax as well both evaluating directly or using the /edit
:
Yet, the following options can be made to work out effectively to make use of existing modules within JShell along with the snippet evaluations -
--module-path <path>
Specify where to find application modules
--add-modules <module>(,<module>)*
Specify modules to resolve, or all modules on the
module path if <module> is ALL-MODULE-PATHs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With