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