在Java 9中的JShell中创建模块 [英] Create Module in JShell in Java 9

查看:59
本文介绍了在Java 9中的JShell中创建模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只需探索Java的新版本,其新的模块系统,以及jshell.也许我的问题没有太多道理,但我很好奇.

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.

所以我想到了一个问题:有什么方法可以在jshell中创建模块?还是只能在module-info.java中创建模块?

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?

推荐答案

当前无法使用JShell创建模块,并且它不是 JShell的目标.

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

JShell API将提供JShell的所有评估功能. 输入到API的代码片段称为 "snippets" . jshell工具还将使用JShell完成API 确定何时输入不完整(并且必须提示用户输入 更多),如果添加了分号,将是完整的(其中 工具会附加分号)以及如何完成 使用制表符请求完成时输入.

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.

代码段必须与以下JLS语法生成之一相对应:

A snippet must correspond to one of the following JLS syntax productions:

  • 表达
  • 声明
  • ClassDeclaration
  • InterfaceDeclaration
  • MethodDeclaration
  • FieldDeclaration
  • ImportDeclaration
  • Expression
  • Statement
  • ClassDeclaration
  • InterfaceDeclaration
  • MethodDeclaration
  • FieldDeclaration
  • ImportDeclaration

snippet可能未声明软件包或模块.所有JShell代码都放在单个包中的未命名的模块 .程序包的名称由JShell控制.

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.

实际上,尝试在JShell中使用ModuleDeclaration既不是公认的语法,也不是直接评估还是使用/edit:

In fact trying to use a ModuleDeclaration within JShell is not a recognized syntax as well both evaluating directly or using the /edit:

但是,可以做出以下选择以有效地利用JShell中的现有模块以及代码段评估-

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

这篇关于在Java 9中的JShell中创建模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆