简体   繁体   中英

Create Module in JShell in Java 9

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 ?

Modules cannot be created using JShell currently and it is not a Goal of JShell either.

JShell Functionality

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:

  • Expression
  • Statement
  • ClassDeclaration
  • InterfaceDeclaration
  • MethodDeclaration
  • FieldDeclaration
  • ImportDeclaration

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM