DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > A Look at IntelliJ IDEA's Support for Java 9 Modules

A Look at IntelliJ IDEA's Support for Java 9 Modules

Although Java 9 isn’t expected just yet, IntelliJ IDEA 2017.1 provides support for working with Java 9 modularity (Jigsaw), including code completion and quick fixes.

Trisha Gee user avatar by
Trisha Gee
·
Mar. 23, 17 · Java Zone · News
Like (10)
Save
Tweet
11.86K Views

Join the DZone community and get the full member experience.

Join For Free

IntelliJ IDEA 2017.1 brings support for Java 9’s new modularity (Project Jigsaw). In this latest version, support includes code completion in the module-info.java file, and quick fixes for adding modules to your project.

Let’s take a look at a basic example of a modular project. To start with, we just have an ordinary IntelliJ IDEA module that contains a simple “Hello World” type application.

A simple application

IntelliJ IDEA lets you create a new module-info.java for your module.

Create new module-info.java

This module-info.java will have the basic structure provided for you.

Default module-info.java

Everything continues to work as expected with this file in place, for example running the application works normally. Where you start to see the impact of using modularity is when you try to use Java classes that you’d normally be able to access.

Error using Logger

Here, IntelliJ IDEA can help you to figure out what the problem is, and offer suggestions to fix it.

Add requires to module-info.java

As you’d expect, IntelliJ IDEA makes the correct changes to the module-info.java file.

Requires added

Of course, you can edit the module-info.java file yourself, and the IDE offers code completion and suggestions.

Code completion in module-info.java

Quick fixes are not only available for the standard Java modules, but also to help you write modular code yourself.  If you’re trying to access code that belongs in another IntelliJ IDEA module, from inside a module that uses Java 9’s modularity (indicated by the presence of a module-info.java file), IntelliJ IDEA will show you this isn’t going to work without some more changes.

Using other modules

Firstly, there’s more code completion available to help you make the changes to the module you need to access. So once you’ve got a module-info.java file in the module you want to use, you can quickly export the required packages.

Code completion for exports

Back in the module that needs to use this newly exported code, using Alt and Enter gives suggestions as to how to fix the problems. There are two steps in this case: firstly, the IntelliJ IDEA module one needs to have a dependency on the IntelliJ IDEA module two.  Once this is done, then the module-info.java file for module one can be updated to show that the module requires module two.

Quick fixes for using modules

It’s important to note that there are two systems of modularly here: firstly, the IntelliJ IDEA modules that you’re probably already familiar with; and secondly, the new Java 9 (Jigsaw) modules that are configured using module-info.java.  To use Java 9 modularity, each Java 9 module needs to correspond to an IntelliJ IDEA module. Also note that (as shown in the last example) in IntelliJ IDEA 2017.1 you need to declare your IntelliJ IDEA module dependencies as well as your Java 9 module dependencies. So in the last example, module one was dependent upon module two:

IntelliJ IDEA module dependencies

But it also needed to declare that it requires module two in module-info.java.

Module-info dependency

In summary, although Java 9 isn’t expected just yet, IntelliJ IDEA 2017.1 provides support for working with Java 9 modularity (Jigsaw), with code completion, quick fixes and help for using the new module system.

If you want to start working with Jigsaw, check out the OpenJDK Quick Start guide, download IntelliJ IDEA 2017.1 and take a look at our Getting Started with Java 9 tutorial.

intellij Java (programming language)

Published at DZone with permission of Trisha Gee, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Complete Guide to TestOps
  • Python Class Attribute: Class Attribute vs. Instance Attribute
  • Legacy Modernization and Hybrid Cloud with Kafka in Healthcare
  • Event-Driven Microservices?

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo