- Modular Programming in Java 9
- Koushik Kothagal
- 364字
- 2021-07-02 18:38:21
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:
- The location of the compiled modules--also called the module path.
- The module that contains the class with the main method that needs to start the execution.
- 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.
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.
- 深入理解Android(卷I)
- Objective-C應用開發全程實錄
- 前端跨界開發指南:JavaScript工具庫原理解析與實戰
- HTML5 and CSS3 Transition,Transformation,and Animation
- Scientific Computing with Scala
- Asynchronous Android Programming(Second Edition)
- Building RESTful Python Web Services
- ANSYS Fluent 二次開發指南
- Java程序設計入門
- Mastering Linux Security and Hardening
- Android移動開發案例教程:基于Android Studio開發環境
- 人工智能算法(卷1):基礎算法
- SpringBoot從零開始學(視頻教學版)
- Android熱門應用開發詳解
- Visual FoxPro數據庫程序設計