O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. As the older version of Java that is, Java 8 and before don't support modules, we would have to get rid of the module-info.java while compiling on an older version. So what we did was to not include module-info.java during our compilation. So we compiled using the following code:
      $ javac --release 8 -d mods src\demo\com\packt\CollectionsDemo.java

You can see that we are using the --release option targeting Java 8 and not compiling the module-info.java.

  1. Let's create a JAR file because it becomes easier to transport the java build instead of copying all the class files:
      $jar --create --file mlib/demo.jar --main-class       com.packt.CollectionsDemo -C mods/ .
  1. Let's run the preceding JAR in Java 9:
      $ java -version java version ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required