只是探索新的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-PATHsModules 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 ImportDeclarationA 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更多推荐
发布评论