1.3K Followers
·
Follow

Using JDK 9 with Project Jigsaw in IntelliJ IDEA

The Java platform module system, known under the codename Project Jigsaw, is the main feature of Java 9. If you’re not familiar yet with this feature, I recommend you to watch one of the talks about it, or read its design overview by Mark Reinhold.

In short, Project Jigsaw is aimed at replacing the error-prone “classpath” with a reliable configuration as well as breaking the monolithic JDK into modules that could be deployed and used independently.

Though the release of Java 9 is scheduled for March, 2017, an early preview of the JDK 9 with Project Jigsaw is available. For those who’d like to play with modules and learn how to define them, there is a step-by-step tutorial.

Since the implementation of the module system is under heavy development and may change, IntelliJ IDEA doesn’t provide official support for it yet. I expect it to appear closer to June, 2016 when the feature hits Feature Complete. However if you’d like to try Jigsaw with IntelliJ IDEA already, below you’ll find instructions on that. Note that the standard JDK9 can be used with IntelliJ IDEA without any limitations — just as any other JDK.

How to configure an IntelliJ IDEA project that uses Jigsaw

1) Download the JDK 9 with Project Jigsaw (not to be confused with the standard JDK 9).

2) Configure a separate IntelliJ IDEA module for each Jigsaw module:

Image for post
Image for post

3) Specify dependencies between IntelliJ IDEA modules according to your module-info.java files:

Image for post
Image for post

4) Tune the Java compiler options in SettingsBuild, Execution, DeploymentCompilerJava Compiler by adding the “modulepath” parameter pointed to the project output directory:

Image for post
Image for post

5) Make the project via Ctrl + F9 (Cmd + F9 for OS X)

6) The trickiest thing now is how to run the application. If you want the JRE to load the services defined in your modules, instead of the “classpath” you have to use the “modulepath” parameter. This is something IntelliJ IDEA doesn’t allow you to do in the Run configuration dialog. In overcome this limitation, run your application using the command line from the built-in Terminal:

Image for post
Image for post

I hope you’ll find these instructions useful.

Since IntelliJ IDEA 16 EAP is all in progress, visit the IntelliJ IDEA blog for news about the Jigsaw support.

Written by

Co-founder @dstackai. Product @PyCharm and @BigDataToolsJB.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store