在Java 9中的JShell中创建模块(Create Module in JShell in Java 9)

编程入门 行业动态 更新时间:2024-10-24 03:21:33
在Java 9中的JShell中创建模块(Create Module in JShell in Java 9) java

只是探索新的Java版本,新的模块系统,以及使用jshell。 可能我的问题没有太多意义,但我只是好奇。

所以我想出了这个问题:有没有办法在jshell中创建一个模块? 或者模块只能在module-info.java创建?

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?

最满意答案

目前无法使用JShell创建模块,也不是JShell的目标 。

JShell功能

JShell API将提供所有JShell的评估功能。 输入到API的代码片段被称为"snippets"jshell工具还将使用JShell完成API来确定何时输入不完整 (并且必须提示用户输入更多内容), 如果添加了分号 (在这种情况下,该工具将附加分号), 那么它将完成 如果完成请求时使用选项卡,如何完成输入。

代码片段必须符合以下JLS语法产品之一:

表达 声明 ClassDeclaration InterfaceDeclaration MethodDeclaration FieldDeclaration 导入声明

snippet可能不会声明包或模块 。 所有的JShell代码都放在一个未命名模块单个包中 。 包的名称由JShell控制。

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

在这里输入图像描述


然而,可以通过以下选项来有效地利用JShell中的现有模块以及片段评估 -

--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

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:

enter image description here


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

更多推荐

本文发布于:2023-07-25 22:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1267189.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模块   JShell   Java   Create   Module

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!