sormuras.github.io

🎼 Bach.java - Intro 1 - Greetings!

Welcome to a series of blog posts describing how Bach.java builds a modular Java project.

This initial introduction prepares the foundation for more blog posts to come. The felt ratio of 99% IDEA-related sections to only 1% relevant for Bach.java is on purpose. Later posts will build upon this one and only refer to IDEA-related instructions covered here.

TL;DR

Fast-forward to the Build Modular Java Project with Bach.java section.

The remainder and the majority of the text sections below is about setting up IntelliJ IDEA for a modular Java project. In order to not re-invent wheels this blog borrows ideas and replays commands from the Module System Quick-Start Guide. It doesn’t hurt to (re-)visit that guide before reading on.

Without further a do, let’s start hacking … erm, clicking!

Prerequisite

New Java Project

Enter Basic Project Properties

Fine-tune Project Settings

IDEA created an initial project structure. Some settings require a fine-tune pass.

IDEA has its own idea of storing all Java sources of an IDEA module in a nested src/ directory. In the following, we’ll delete and unmark such a src/ directory twice. Once per created IDEA module. Without the src/ directories the structure matches the example from the Quick-Start Guide better.

Add IDEA Module com.greetings

Let’s create an IDEA module named com.greetings. It will host the Java module with the same name.

Yes, as mentioned above, the hereby automatically created src/ directory will be deleted.

Every IDEA module that hosts Java source files mandates at least a single Sources Folder to be selected. Here, the content root directory of the just created IDEA module is marked as such.

Add Java Module Descriptor com.greetings

With IDEA’s project structure set up and fine-tuned, let’s add Java source files. The Quick-Start Guide Greetings example reads:

The module consists of two source files: the module declaration (module-info.java) and the main class.

IDEA just generated an empty, yet proper Java Module Declaration for us!

Add Main Class com.greetings.Main

After declaring the Java module com.greetings, now it’s the turn of the main program.

IDEA just generated an empty Main.java file and stored in package com.greetings.

That’s it. All is set up for running the program.

Run Main Class with IDEA

Build Modular Java Project with Bach.java

Finally…

Wait some seconds to let the zero-installation feature bootstrap Bach.java and build the project.

Done.

Want more?

Here’s a short video showing Bach 11.8 in action: https://youtu.be/LyJ9BfZfEsI

https://github.com/sormuras/simplicissimus