右键-New-Module,输入模块基本信息
新建module-info.java文件
输入module-info.java内容如下:
module helloworld {
exports com.hello;
}
新建HelloWorld.java
文件
package com.hello;
import java.util.Calendar;
public class HelloWorld {
public String sayHelloWorld() {
return String.format("%s, now is %s", "hello world", Calendar.getInstance().getTime());
}
}
最终模块内容如下
参照上述步骤新建模块helloworldclient
其中,module-info.java
内容如下:
module helloworldclient {
requires com.hello;
}
HelloWorldClient.java内容如下:
package com.hello.client;
import com.hello.HelloWorld;
public class HelloWorldClient {
public static void main(String[] args) {
HelloWorld hello = new HelloWorld();
System.out.println(hello.sayHelloWorld());
}
}
执行HelloWorldClient,得到如下结果
hello world, now is Thu Nov 15 11:52:29 CST 2018