100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > Java SE 9:使用Eclipse和IntelliJ IDEA IDE开发和测试HelloWorld模块(第4部分)

Java SE 9:使用Eclipse和IntelliJ IDEA IDE开发和测试HelloWorld模块(第4部分)

时间:2020-10-05 04:25:22

相关推荐

Java SE 9:使用Eclipse和IntelliJ IDEA IDE开发和测试HelloWorld模块(第4部分)

I have already discuss about “Java Module System” Basics in my previous posts. I’m going to discuss about “How to develop and test a Simple HelloWorld Java 9 Module by using the two popular IDEs: Eclipse and IntelliJ IDEA” in this post.

我之前的文章中已经讨论过“ Java模块系统”基础知识。 我将在本文中讨论“如何使用两种流行的IDE开发和测试简单的HelloWorld Java 9模块:Eclipse和IntelliJ IDEA”。

In this series of “Java Module System” posts, it is my fourth 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模块系统”系列文章中,这是我的第四篇文章。 在阅读本文之前,请单击以下链接以浏览我的上一篇文章,以了解有关Java 9 Modules的一些基础知识。

Introduction to Java 9 Module SystemJava 9模块系统简介 Java 9 Module and Module Descriptor BasicsJava 9模块和模块描述符基础知识 HelloWorld Module With CMD Prompt带CMD提示的HelloWorld模块

Now, Let us start developing HelloWorld and it’s clients Modules.

现在,让我们开始开发HelloWorld及其客户端模块。

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

Dev Environment Setup for Eclipse IDE and JDK 9Eclipse IDE和JDK 9的开发环境设置 Develop “HelloWorld” Module With Eclipse IDE使用Eclipse IDE开发“ HelloWorld”模块 Develop and Test “HelloWorldClient” Module With Eclipse IDE使用Eclipse IDE开发和测试“ HelloWorldClient”模块 Develop “HelloWorld” Module With IntelliJ IDEA IDE使用IntelliJ IDEA IDE开发“ HelloWorld”模块 Develop and Test “HelloWorldClient” Module With IntelliJ IDEA IDE使用IntelliJ IDEA IDE开发和测试“ HelloWorldClient”模块

I have already discussed about “HelloWorld” and “HelloWorldClient” Modules requirements in my third post’s first section. Please read HelloWorld Module With CMD Prompt once before going through the next sections.

在第三篇文章的第一部分中,我已经讨论了“ HelloWorld”和“ HelloWorldClient”模块的要求。 在进行下一部分之前,请先阅读带有CMD提示的HelloWorld模块 。

Eclipse IDE和JDK 9的开发环境设置 (Dev Environment Setup for Eclipse IDE and JDK 9)

I’m going to use “Eclipse Oxygen M4” with “JDK 1.9 EA (Early Access)” to develop our application. Please download and setup Eclipse and JDK Softwares.

我将使用“ Eclipse Oxygen M4”和“ JDK 1.9 EA(Early Access)”来开发我们的应用程序。 请下载并设置Eclipse和JDK软件。

Add JDK 9 Path to “Eclipse Installed JREs” as shown below:

将JDK 9路径添加到“ Eclipse Installed JRE”,如下所示:

使用Eclipse IDE开发“ HelloWorld”模块 (Develop “HelloWorld” Module With Eclipse IDE)

Create a Java project “com.hello” by selecting “JDK 9 EA” option as shown below:通过选择“ JDK 9 EA”选项创建一个Java项目“ com.hello”,如下所示: Create our required Source folder “com.hello” by selection “module-info.java” option as shown below. This source folder is the root folder of our HelloWorld Module.通过选择“ module-info.java”选项创建所需的源文件夹“ com.hello”,如下所示。 该源文件夹是我们的HelloWorld模块的根文件夹。

This step creates default module-info.java file at Module root folder as shown below:

此步骤在模块根文件夹下创建默认的module-info.java文件,如下所示:

Create a package “com.hello”. Then develop ourHelloWorld.javacomponent.创建一个包“ com.hello”。 然后开发我们的HelloWorld.java组件。

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

Export package to other Modules in module-info.java as shown below:如下所示,将包导出到module-info.java中的其他模块:

module com.hello {exports com.hello;}

That’s it about “HelloWorld” Module development. Final “HelloWorld” Module project structure looks like below:

关于“ HelloWorld”模块开发就是这样。 最终的“ HelloWorld”模块项目结构如下:

Let us move to “HelloWorldClient” Module development in next section.

在下一节中,让我们转到“ HelloWorldClient”模块开发。

使用Eclipse IDE开发和测试“ HelloWorldClient”模块 (Develop and Test “HelloWorldClient” Module With Eclipse IDE)

Fallow Same “HelloWorld” Module steps to “HelloWorldClient” Module.

相同的“ HelloWorld”模块进入“ HelloWorldClient”模块。

Create “com.hello.client” project.创建“ com.hello.client”项目。 Create Source folder “com.hello.client” with “module-info.java”.使用“ module-info.java”创建源文件夹“ com.hello.client”。 Create “HelloWorldClient.java” component under “com.hello.client” package.在“ com.hello.client”包下创建“ 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());}}

Update “module-info.java” to import “com.hello” to use Hello.java in “HelloWorldClient.java” component.更新“ module-info.java”以导入“ com.hello”以在“ HelloWorldClient.java”组件中使用Hello.java。

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

Now if you see the “module-info.java” in Eclipse IDE, it shows an error as shown below.现在,如果您在Eclipse IDE中看到“ module-info.java”,它将显示一个错误,如下所示。

As “com.hello” Module is not in “com.hello.client” build path, it is showing that error message.

由于“ com.hello”模块不在“ com.hello.client”构建路径中,因此显示该错误消息。

Let us add “com.hello” project to “com.hello.client” build path as shown below:

让我们将“ com.hello”项目添加到“ com.hello.client”构建路径,如下所示:

It resolves Module dependency and also solves import statements issues.

它解决了模块依赖性,还解决了导入语句问题。

Final “com.hello.client” Module project structure looks like below.最终的“ com.hello.client”模块项目结构如下所示。

Test “HelloWorld” Module With Eclipse IDE

To test our Modules, right click on “HelloWorldClient.java” and select “Run As” >> “Java application” to see the following output:

使用Eclipse IDE测试“ HelloWorld”模块

要测试我们的模块,请右键单击“ HelloWorldClient.java”,然后选择“运行方式” >>“ Java应用程序”以查看以下输出:

Hello World!

It is similar to our “CMP Prompt” example. There is no difference between Part-3 and this example, except Commands and IDEs.

它类似于我们的“ CMP Prompt”示例。 第3部分与本示例之间没有什么区别,除了命令和IDE。

使用IntelliJ IDEA IDE开发“ HelloWorld”模块 (Develop “HelloWorld” Module With IntelliJ IDEA IDE)

To develop and test “HelloWorld” Module, I’m going to use latest version of IntelliJ IDEA:IDEA .1 EAP.

为了开发和测试“ HelloWorld”模块,我将使用IntelliJ IDEA的最新版本:IDEA .1 EAP

You can download this software from this link:

/display/IDEADEV/IDEA+.1+EAP

您可以从以下链接下载此软件:

/display/IDEADEV/IDEA+.1+EAP

Open IntelliJ IDEA and click on “Create New Project” option as shown below打开IntelliJ IDEA,然后单击“创建新项目”选项,如下所示 Select “Java” from left side List and add your JDK 9 as shown below从左侧列表中选择“ Java”,然后添加您的JDK 9,如下所示

Click on “Next” and “Next” buttons.

单击“下一步”和“下一步”按钮。

Provide Project name: “helloworld”提供项目名称:“ helloworld”

Click on “Finish” button. This step creates our base project.

点击“完成”按钮。 此步骤将创建我们的基础项目。

Create “com.hello” Module under “helloworld” Project在“ helloworld”项目下创建“ com.hello”模块 Create “module-info.java” file.创建“ module-info.java”文件。

Then create a package “com.hello” and Create “HelloWorld.java” file.

然后创建一个包“ com.hello”并创建“ HelloWorld.java”文件。

NOTE:-Please copy content from Eclipse IDE examples to “module-info.java” and “HelloWorld.java” files.

注意:-请把内容从Eclipse IDE示例复制到“ module-info.java”和“ HelloWorld.java”文件中。

使用IntelliJ IDEA IDE开发和测试“ HelloWorldClient”模块 (Develop and Test “HelloWorldClient” Module With IntelliJ IDEA IDE)

In the same way, Create “com.hello.client” Module under “helloworld” Project同样,在“ helloworld”项目下创建“ com.hello.client”模块

Create and copy content from from Eclipse IDE examples to “module-info.java” and “HelloWorldClient.java” files.

创建内容并将内容从Eclipse IDE示例复制到“ module-info.java”和“ HelloWorldClient.java”文件中。

Now, we have developed both Modules successfully. However, if you observe in the bottom left corner of IDE, we will see one error (Similar to Eclipse IDE error).

现在,我们已经成功开发了两个模块。 但是,如果您在IDE的左下角观察到,我们将看到一个错误(类似于Eclipse IDE错误)。

To resolve this issue, we need to add “com.hello” Module as dependency.

要解决此问题,我们需要添加“ com.hello”模块作为依赖项。

Add “com.hello” Module as dependency to “com.hello.cleint” Module as shown below.如下所示,将“ com.hello”模块作为依赖项添加到“ com.hello.cleint”模块。

Click on “Open Module Settings” option as shown below:

单击“打开模块设置”选项,如下所示:

Add “com.hello” Module.

添加“ com.hello”模块。

Click on “OK” button. It resolves all issues.

点击“确定”按钮。 它解决了所有问题。

Right click on “HelloWorldClient.java” and run the program.右键单击“ HelloWorldClient.java”并运行程序。

You can see the output and complete Project and Modules structure in the below diagram

您可以在下图中看到输出以及完整的Project和Modules结构

Wow, Congratulations!

哇,恭喜!

We are successfully developed and tested our Favourite “HelloWorld” Module example using two popular IDEs.

我们已经使用两个流行的IDE成功开发并测试了我们最喜欢的“ HelloWorld”模块示例。

That’s it all about “Developing and Testing a Simple HelloWorld Java 9 Module by using Eclipse and IntelliJ IDEA IDEs”. We will discuss some more new and complex concepts about Java SE 9 Modules Development in my coming posts.

这就是“使用Eclipse和IntelliJ IDEA IDE开发和测试简单的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学习愉快!

翻译自: /13630/javase9-helloworld-module-ides-part4

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。