We have discussed Java 9 Modularity and Module System. Refer for more details.

Here we will discuss how to create module in Java 9 with Eclipse IDE, Listed steps will guide to setup the environment.

  • Environment Setup for Eclipse IDE with JDK 9

    Download Latest version of eclipse and extract zip in a system, I am using eclipse Oxygen.
    Download JDK 9 and install the same.

    As JDK image is now changed to modular, We can not add JDK directly in build-path. To set JDK 9 as your run environment, we need to add extra plugin which developed by Eclipse Community itself.

    Go to Eclipse Market Place and Search for Java 9 Support, You will get Java 9 Support (BETA) for Oxygen. Click on Install.

    Once plugin is installed, Add JDK 9 in your Installed JREs list, So that while creating a new module it will be added in build-path your project.

    Go to Window > Preferences. Click on Java > Installed JREs. Under Installed JRE scrin Click on add button. Click on Standard VM and Next, Browse JDK path and click on Finish. Select JDK 9 as default to be added in any new project, And we are ready to create our first module.

  • Create HelloWorld Module in Eclipse

    Create a new Java Project and provide Project name and check JRE.

    Create a new Java Project and provide Project name and check JRE

    Create a class HelloWorld under package com.codenuclear

    Class is created, Let’s create module descriptor file.

    Right click on project and go to Configure > Create module-info.java

    After creating module descriptor file directory structure looks like.

    module-info.java
    HelloWorld.java
  • We have exposed HelloWord module in module descriptor, Lets consume it from other module.

  • “HelloWorldTest” Module With Eclipse

    Follow same steps as HelloWord module to HelloWorldTest module.

    • Create a Project HelloWorldTest
    • Create a Class HelloWorldTest under com.nuclear package.
    • Create a module descriptor file[module-info.java].

    After creating module descriptor file directory structure looks like.

    To use HelloWorld Class in HelloWorldTest project we have to add HelloWorld Project in build-path of Test Project. Go to build-path and add it.

    Though we have added HelloWorld project in a build-path, We can not assess resources of that, To do so we have to tell module descriptor that we need a HelloWorld module resource by making entry of requires HelloWorld in module-info.java

    module-info.java
    HelloWorldTest.java

    We are good to go now, Right click on HelloWorldTest.java file and select Run As > Java application

  • Run Result
    Good Morning, Folks !!

    That’s for the day, Hope you enjoyed an article, Keep Learning and Sharing !! 🙂

It's good to share...Share on FacebookTweet about this on TwitterShare on LinkedInPin on PinterestShare on Google+Email this to someone

3 Thoughts on “How to create Module in Java 9 with Eclipse”

Leave a Reply

Your email address will not be published. Required fields are marked *