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

Compiling your module

Compiling code in a Java 9 module requires the use of the javac command as always, but with a few different options this time. To compile modules in Java 9, you need to provide the javac command with the following information:

  1. The location of your modules. This is the directory that contains the module root folders for all the modules in your application. In our case, this is the src folder. In it, we just have one module root folder.
  2. The paths and names of the Java files that need to be compiled. In our case, it's just one file--Main.java.
  3. The destination location where the compiler needs to output the compiled .class files. This can be any location, but I recommend choosing a folder named out directly below the project root folder.

To compile the module you've written, go to the project root (in our example, it's ~/code/java9) and run the following command:

Here, you are specifying the module source path (1) using the --module-source-path command option, the output directory for compiled classes (2) using the -d command option, and the list of Java source files (3) by specifying them directly in the command (in this case, Main.java and module-info.java).

If the compiler is successful, there is no output to the console. The out directory should contain the compiled classes:

Note that there is a one-to-one mapping between the source and compiled classes. Even the module descriptor module-info.java has been compiled to a .class file--module-info.class. This is for a very important reason. The module configuration provides metadata information about the module not just to the compiler during compile time, but also to the JVM during runtime. Thanks to the module-info.class, the JVM also has all the information about every Java module, thus enabling the runtime to tap into many of the benefits of the module system during execution.

主站蜘蛛池模板: 万荣县| 正宁县| 武冈市| 中江县| 来宾市| 五河县| 灌南县| 宜宾县| 耿马| 汕尾市| 腾冲县| 阳高县| 丰台区| 桐乡市| 左贡县| 泽普县| 白城市| 新干县| 松滋市| 湘西| 承德县| 肥乡县| 吴桥县| 琼海市| 鄄城县| 晋江市| 舒兰市| 奈曼旗| 会昌县| 武乡县| 眉山市| 乾安县| 贵阳市| 鄱阳县| 磐石市| 河间市| 临清市| 隆德县| 内丘县| 潜山县| 贡觉县|