官术网_书友最值得收藏!

Executing your module

Executing your compiled code again uses the familiar java command, but with some new options. Here is the information you need to tell the java command in this case:

  1. The location of the compiled modules--also called the module path.
  2. The module that contains the class with the main method that needs to start the execution.
  3. The class with the main method in the preceding module that needs to start the execution.

To execute the code you just compiled in the previous step, you'd need to run the following command in the same directory:

Here, you are specifying the location of the compiled modules (1) using the --module-path flag. We've told the compiler in the previous step to place our compiled code in the out folder, and so that's the value we need to provide here. You specify the module (2) and the class with the main method (3) using the --module option. Note the format of the value--it's <module-name>/<fully-qualified-classname>. Here, our code consists of just one class, so it feels unnecessary to specify this, but you can imagine a code base with multiple modules and classes, many of which might have main methods. It's important for the runtime to know which main method of which class of which module it needs to start the execution on.

There are alternative option names for many of these options. For example, instead of using --module-path, you can simply use -p, and --module can be replaced with -m.

If the execution completed successfully, you should see the message Hello World! printed on the console.

You've learned about two new arguments, --module-source-path and --module-path. They roughly correspond to the -sourcepath and -classpath options that we've been using in Java for a while now.

Java 8 and earlier:

sourcepath: Tells the compiler where the source files are that need to be compiled.

classpath: Tells the compiler/runtime where the compiled types are that need to be included in the classpath for compiling/running code.

Java 9:

module-source-path: Tells the compiler where the source files for the modules are.

module-path: Tells the compiler/runtime where the compiled modules are that need to be considered for compiling/running code your code.
主站蜘蛛池模板: 贵德县| 宾阳县| 雅江县| 广东省| 英超| 房山区| 明光市| 色达县| 洛南县| 宽城| 连南| 金昌市| 金堂县| 墨脱县| 新龙县| 高要市| 南宁市| 广饶县| 广饶县| 永和县| 岳普湖县| 出国| 宝山区| 湖南省| 太仆寺旗| 镇宁| 巨野县| 中卫市| 赤壁市| 九江县| 札达县| 五原县| 蕲春县| 木兰县| 万山特区| 云林县| 信丰县| 浦县| 通辽市| 崇明县| 林口县|