java cmd测试

I have already discuss few theoretical concepts about Java 9 Module System in my previous posts: “Java Module System”, “Module” and “Module Descriptor”. I’m going to discuss about “How to develop and test a Simple HelloWorld Java 9 Module by using Command (CMD) prompt” in this post.

在我以前的文章中,我已经讨论了关于Java 9模块系统的一些理论概念:“ Java模块系统”,“模块”和“模块描述符”。 我将在本文中讨论“如何通过使用命令(CMD)提示符开发和测试简单的HelloWorld Java 9模块”。

In this series of “Java 9 Module System” posts, it is my third post. Before reading this post, please go through my previous post by clicking the following links to understand some basics about Java 9 Modules.

在这一系列“ Java 9 Module System”文章中,这是我的第三篇文章。 在阅读本文之前,请单击以下链接以浏览我的上一篇文章,以了解有关Java 9 Modules的一些基础知识。

  • Introduction to Java 9 Module SystemJava 9模块系统简介
  • Java 9 Module and Module Descriptor BasicsJava 9模块和模块描述符基础知识

We have already discussed too much theory. Now, Let us start developing some simple Modules.

我们已经讨论了太多的理论。 现在,让我们开始开发一些简单的模块。

发表简要目录: (Post Brief Table of Content:)

  • Introduction to “HelloWorld” Module“ HelloWorld”模块简介
  • Steps to Develop a Java 9 Module开发Java 9模块的步骤
  • Develop “HelloWorld” Module开发“ HelloWorld”模块
  • Develop “HelloWorldClient” Module开发“ HelloWorldClient”模块
  • Set Java SE 9 Environment设置Java SE 9环境
  • Compile “HelloWorld” Module编译“ HelloWorld”模块
  • Compile “HelloWorldClient” Module编译“ HelloWorldClient”模块
  • Test “HelloWorldClient” Module测试“ HelloWorldClient”模块

“ HelloWorld”模块简介 (Introduction to “HelloWorld” Module)

As a Developer, we first start with “HelloWorld” program to learn new Concept or Programming Language. In the same way, we start learning our Java 9 New concept “Modular Programming” with “HelloWorld” Module development.

作为开发人员,我们首先从“ HelloWorld”程序开始学习新的概念或编程语言。 以同样的方式,我们开始通过“ HelloWorld”模块开发来学习Java 9新概念“ 模块化编程 ”。

In this post, we are going to develop the following two modules:

在本文中,我们将开发以下两个模块:

  • com.hellocom.hello
  • com.hello.clientcom.hello.client

Our requirements for these two modules are:

我们对这两个模块的要求是:

  • com.hello module develops “HelloWorld” component.com.hello模块开发“ HelloWorld”组件。
  • com.hello module exports com.hello package to outside world.com.hello模块将com.hello包导出到外部。
  • com.hello.client module requires or imports com.hello module.com.hello.client模块需要或导入com.hello模块。
  • com.hello.client module uses “HelloWorld” component.com.hello.client模块使用“ HelloWorld”组件。

This complete problem statement is depicted as shown below:

完整的问题陈述如下所示:

Let us start developing our modules in the coming sections.

让我们在接下来的部分开始开发模块。

开发Java 9模块的步骤 (Steps to Develop a Java 9 Module)

We will follow these steps one by one to develop and test our “HelloWorld” Module.

我们将一步一步地遵循这些步骤来开发和测试“ HelloWorld”模块。

  • Create Module name folder, for example “com.hello”.创建模块名称文件夹,例如“ com.hello”。
  • Create Module Packages, for example “com.hello”.创建模块包,例如“ com.hello”。
  • Create our Java component, for example “HelloWorld.java”.创建我们的Java组件,例如“ HelloWorld.java”。
  • Create Module Descriptor, for example “module-info.java”.创建模块描述符,例如“ module-info.java”。
  • Define Module Description in Module Descriptor, for example “exports com.hello;” of “module-info.java” in “com.hello” module.在模块描述符中定义模块描述,例如“ exports com.hello;” “ com.hello”模块中“ module-info.java”的内容。
  • Create Module Jars if required.如果需要,创建模块罐。
  • Test our modules.测试我们的模块。

These steps are common for almost all modules development. Most of the commands used in this post are applicable to Windows OS. Few commands may differ for other OSs like Linux, Mac.

这些步骤几乎适用于所有模块开发。 本文中使用的大多数命令都适用于Windows OS。 对于其他操作系统,如Linux,Mac,很少有命令会有所不同。

开发“ HelloWorld”模块 (Develop “HelloWorld” Module)

We first start with “HelloWorld” Module development. Please refer our Problem statement diagram for more details.

我们首先从“ HelloWorld”模块开发开始。 请参阅我们的问题陈述图以获取更多详细信息。

Create “HelloWorld” Module name folder: com.hello

创建“ HelloWorld”模块名称文件夹:com.hello

mkdir com.hello

Create “HelloWorld” Module package name folder: com\hello

创建“ HelloWorld”模块程序包名称文件夹:com \ hello

mkdir com.hello\com\hello

Please refer the following diagram for the above two steps:

以上两个步骤请参考下图:

Develop “HelloWorld.java” component under package name “com.hello\com\hello”.

以包名称“ com.hello \ com \ hello”开发“ HelloWorld.java”组件。

HelloWorld.java

HelloWorld.java

package com.hello;public class HelloWorld {public String sayHelloWorld() {return "Hello World!";}}

Develop Module Descriptor at Module root folder “com.hello”.

在模块根文件夹“ com.hello”处开发模块描述符。

module-info.java

module-info.java

module com.hello {exports com.hello;}

If we observe this Module Descriptor, we can say that “com.hello” is exporting “com.hello” package to outside world so that our HelloWorldClient program can use it.

如果我们观察到此模块描述符,可以说“ com.hello”正在将“ com.hello”包导出到外界,以便我们的HelloWorldClient程序可以使用它。

“com.hello” Module full tree structure as shown below:

“ com.hello”模块的完整树状结构如下图所示:

开发“ HelloWorldClient”模块 (Develop “HelloWorldClient” Module)

Like “HelloWorld” Module, We need to follow the same steps to develop this module. Please refer our Problem statement diagram for more details.

像“ HelloWorld”模块一样,我们需要遵循相同的步骤来开发此模块。 请参阅我们的问题陈述图以获取更多详细信息。

Create “HelloWorldClient” Module name folder: com.hello.client

创建“ HelloWorldClient”模块名称文件夹:com.hello.client

mkdir com.hello.client

Create “HelloWorldClient” Module package name folder: com\hello\client

创建“ HelloWorldClient”模块程序包名称文件夹:com \ hello \ client

mkdir com.hello\com\hello\client

Develop “HelloWorldClient.java” component under package name “com.hello\com\hello\client”.

在包名称“ com.hello \ com \ hello \ client”下开发“ HelloWorldClient.java”组件。

HelloWorldClient.java

HelloWorldClient.java

package com.hello.client;import com.hello.HelloWorld;public class HelloWorldClient {public static void main (String arg[]) {HelloWorld hello = new HelloWorld();System.out.println(hello.sayHelloWorld());}}

Develop Module Descriptor at Module root folder “com.hello”.

在模块根文件夹“ com.hello”处开发模块描述符。

module-info.java

module-info.java

module com.hello.client {requires com.hello;}

If we observe above Module Descriptor, we can say that “com.hello.client” module is using types which are available in “com.hello” package name. It is not exporting anything to the outside world. So other modules cannot access types defined under “com.hello.client” package name.

如果我们观察以上模块描述符,我们可以说“ com.hello.client”模块使用的是“ com.hello”包名称中可用的类型。 它没有向外界出口任何东西。 因此,其他模块无法访问在“ com.hello.client”程序包名称下定义的类型。

Both “com.hello” and “com.hello.client” Modules full tree structure as shown below:

“ com.hello”和“ com.hello.client”都模块完整的树状结构,如下所示:

We have developed our two modules successfully. It’s time to compile them for testing purpose.

我们已经成功开发了两个模块。 是时候编译它们以进行测试了。

设置Java SE 9环境 (Set Java SE 9 Environment)

Almost everyone knows, after installing Java SE 9 EA(Early Access) software we need to set two Environment variables.

几乎每个人都知道,在安装Java SE 9 EA(早期访问)软件之后,我们需要设置两个环境变量。

  • JAVA_HOMEJAVA_HOME
  • PATH路径

As I’m using Java SE 8 for other projects, I’m setting these two variables only at Command Prompt. Please set these variables as System Variables.

当我将Java SE 8用于其他项目时,仅在命令提示符处设置了这两个变量。 请将这些变量设置为系统变量。

NOTE:- If you are new to Java Tools (java,javac and jar) updates to support Java 9 Module System, please go through my post to learn them in-detail:

注意:-如果您不熟悉Java工具(java,javac和jar)的更新以支持Java 9 Module System,请仔细阅读我的文章,以详细了解它们:

Java SE 9 Tools Changes (Link to be updated soon)

Java SE 9 Tools的更改(链接即将更新)

编译“ HelloWorld”模块 (Compile “HelloWorld” Module)

In this section, we will compile our “HelloWorld” first Module.

在本节中,我们将编译“ HelloWorld”第一个模块。

Please use the following javac command to compile this module:

请使用以下javac命令来编译此模块:

F:\Java9ModuleExamples>javac -d output com.hello\com\hello\HelloWorld.java com.hello\module-info.javaOrF:\Java9ModuleExamples>javac -d output com.hello\com\hello\HelloWorld.java F:\Java9ModuleExamples>javac -d output com.hello\module-info.java

Now, “com.hello” module output folder looks like as shown below:

现在,“ com.hello”模块的输出文件夹如下所示:

As our “HelloWorldClient” Module uses this “HelloWorld” Module, we should have com.hello Module Jar file to refer it in Client module. Let us create this using the following jar command.

由于我们的“ HelloWorldClient”模块使用此“ HelloWorld”模块,因此,我们应该有com.hello Module Jar文件在客户端模块中引用它。 让我们使用以下jar命令创建此文件。

jar -c -f mlib\com.hello.jar -C output .

Now our “HelloWorld” Module archieved into a jar file: com.hello.jar which is located at mlib folder as shown below:

现在,我们的“ HelloWorld”模块被归档到一个jar文件中:com.hello.jar,它位于mlib文件夹中,如下所示:

If we observe our “com.hello” module jar file content as shown above, we can see our Module Descriptor is compiled to “module-info.class” file.

如果我们观察到如上所示的“ com.hello”模块jar文件的内容,我们可以看到我们的模块描述符已编译为“ module-info.class”文件。

Before moving to next step, please remove output directory.

在进行下一步之前,请删除输出目录。

F:\Java9ModuleExamples>rmdir /s output
output, Are you sure (Y/N)? YF:\Java9ModuleExamples>mkdir output

编译“ HelloWorldClient”模块 (Compile “HelloWorldClient” Module)

In this section, we will compile our “HelloWorldClient” second Module. Java SE 9 “javac” command supports “module-path” option to refer other modules.

在本节中,我们将编译“ HelloWorldClient”第二个模块。 Java SE 9的“ javac”命令支持“模块路径”选项来引用其他模块。

Please use the following javac command to compile this module:

请使用以下javac命令来编译此模块:

F:\Java9ModuleExamples>javac --module-path mlib -d output com.hello.client\module-info.javaF:\Java9ModuleExamples>javac --module-path mlib -d output com.hello.client\com\hello\client\HelloWorldClient.java

We know our “com.hello.jar” file is located at “mlib” and “com.hello.client” is depending on “com.hello” module.

我们知道我们的“ com.hello.jar”文件位于“ mlib”,“ com.hello.client”取决于“ com.hello”模块。

In order to refer “com.hello” module in “com.hello.client” compilation process, we should use “module-path” to refer “mlib” folder as shown above. Without this path, we cannot compile “com.hello.client” module components.

为了在“ com.hello.client”编译过程中引用“ com.hello”模块,我们应使用“ module-path”来引用“ mlib”文件夹,如上所示。 没有这个路径,我们将无法编译“ com.hello.client”模块组件。

测试“ HelloWorldClient”模块 (Test “HelloWorldClient” Module)

Now, We have compiled both modules successfully. It’s time to test “com.hello.client” module component in this section.

现在,我们已经成功编译了两个模块。 是时候在本节中测试“ com.hello.client”模块组件了。

“com.hello.client” module have a Java component: “HelloWorldClient.java” which contain a main() method so we can run this program as usual using “java” command.

“ com.hello.client”模块具有Java组件:“ HelloWorldClient.java”,其中包含main()方法,因此我们可以使用“ java”命令照常运行该程序。

F:\Java9ModuleExamples>java --module-path mlib -m com.hello.client
Hello World!

Wow, Great News!.
We have successfully developed, compiled and tested “HelloWorld” module now.

哇,好消息!
现在,我们已经成功开发,编译和测试了“ HelloWorld”模块。

That’s it all about “Develop and Test a Simple HelloWorld Java 9 Module by using Command(CMD) Prompt” topic. We will discuss some more concepts about Java SE 9 Modules Development in my coming posts.

关于“使用Command(CMD)提示开发和测试简单的HelloWorld Java 9模块”的主题就足够了。 在我的后续文章中,我们将讨论有关Java SE 9 Modules Development的更多概念。

Please drop me a comment if you like my post or have any issues/suggestions/type errors.

如果您喜欢我的帖子或有任何问题/建议/类型错误,请给我评论。

Thank you for reading my tutorials.

感谢您阅读我的教程。

Happy Java SE 9 Learning!

Java SE 9学习愉快!

翻译自: https://www.journaldev.com/13543/javase9-simple-module-cmd-prompt-part3

java cmd测试

java cmd测试_Java SE 9:使用CMD提示开发和测试简单模块(第3部分)相关推荐

  1. java se与java 的区别_java se与java的区别是什么

    Java是一门程序设计语言,它有三个版本,Java SE(标准版).Java EE(企业版)和Java ME(微型版).而Java SE只是一个使用Java进行编程的规范.框架,它不是一门编程语言.J ...

  2. 转岗测试工作三年经验总结(前端开发转测试)

    时光飞逝,岁月如梭,我从前端开发岗位转入测试岗位已经三年了,这期间从迷茫到熟悉,到强化,到熟练,到总结,感受还是很深的! 三年前的某一个晚上,我正准备下班回家,我们的项目经理把我叫到办公司和我谈话,谈 ...

  3. java 下划线_Java SE 9:“ _”(下划线)更改

    java 下划线 In this post, we will discuss about What is the use of Underscore ("_") in Java M ...

  4. java 运行环境测试_java – 在多个环境中执行JUnit测试的配置

    我有一个包含JUnit测试的 Java项目,需要通过Jenkins在不同的测试环境(Dev,Staging等)上运行. 我目前在不同环境上构建项目以及将url,用户名和密码传递给测试运行器的解决方案是 ...

  5. java lambda函数_Java SE 8新功能介绍:使用Lambda Expression进行函数式编程

    java lambda函数 " Java SE 8新功能浏览 "系列的这篇文章将深入了解Lambda表达式 . 我将向您展示Lambda表达式的几种不同用法. 它们都具有功能接口的 ...

  6. java espresso 自行车_java – 如何在Espresso中重新运行失败的测试? – 头脑风暴

    我想弄清楚,如何使用Espresso重新运行失败的测试.我认为从常见的JUnit测试案例来看,这有点复杂,因为您需要在测试开始之前恢复应用中的状态. 我的方法是创建自己的ActivityTestRul ...

  7. java新建测试程序_java – 如何创建一个CloseableHttpResponse对象来帮助测试?

    我正在尝试构建一个 CloseableHttpResponse模拟对象,以在我的单元测试中返回,但是没有构造函数.我发现这个 DefaultHttpResponseFactory,但它只是一个Http ...

  8. java水印图片_JAVA实用案例之图片水印开发

    写在最前面 上周零零碎碎花了一周的时间研究水印的开发,现在终于写了个入门级的Demo,做下笔记同时分享出来供大家参考. Demo是在我上次写的 JAVA实用案例之文件导入导出(POI方式) 框架基础上 ...

  9. 虹软java接摄像头_Java使用虹软SDK做人脸识别之十分简单的入门

    操作系统:Windows10 64位 编程语言:Java 使用spring boot 开发工具:IDEA 一.下载虹软SDK 进入虹软官网 https://ai.arcsoft.com.cn/ 右上角 ...

最新文章

  1. 在CentOS 6.3 64bit上安装libunwind库
  2. flex 结合sandy引擎创作
  3. 大型网站的负载均衡器、db proxy和db
  4. mysql数据库表的导入导出
  5. 安卓暗黑模式软件_安卓微信暗黑模式(深色模式)怎么开启?手机什么条件才支持?...
  6. C#用正则表达式对IP进行排序
  7. 2021-2025年中国船用辅机行业市场供需与战略研究报告
  8. VBA中,可以利用下面的语句来调用Excel内置对话框
  9. Word vba 替换
  10. 极力推荐--不错的delphi 学习网站与论坛---有待补充
  11. 苹果的airplayer推荐
  12. eclipse中 错误: 找不到或无法加载主类 f.B
  13. 南阳oj 韩信点兵
  14. linux运行搜狗拼音,搜狗输入法 for Linux版的安装图文教程
  15. Android程序员简历
  16. 云原生时代的镜像分发工具——Dragonfly简介
  17. 解决TS中“Cannot find module ‘path‘ or its corresponding type declarations.”
  18. 使用vue echarts 制作地图map
  19. mysql数据库select语句用法_mysql学习笔记之完整的select语句用法实例详解
  20. 苹果CMS插件-苹果CMS必备插件

热门文章

  1. sql 存储过程分页
  2. [转载] python oct_Python oct()
  3. [转载] python截取指定字符串_python字符串截取,python字符串切片的方法详解
  4. [转载] numpy入门4:线性代数
  5. fedora30删除 gnome自带的Videos软件
  6. ethtool---查看网卡
  7. 排序类问题度量指标:Recall , MAP,MRR
  8. Yoga安装Ubuntu后,wifi和亮度调节问题
  9. 使用图片拉伸resizableImageWithCapInsets
  10. [转] Python标准库的threading.Thread类