Modules Make javac Easy

submited by
Style Pass
2024-06-09 23:30:02

I figure this wouldn't be known widely - its not that popular for people to use javac directly these days - but its interesting.

But, if your source files might not directly reference each other, you need to list every file in your project. That turns into something like this.

I.E. with a directory that has the same name as the module within it - then javac can automatically find and compile your code.

So --module-source-path tells it where to find all the code for a module and --module tells it what module you want to compile.

If you wanted all your code in a src/ folder you can do that as well. You just need to tweak the --module-source-path argument.

Once you've laid out your code like this other tools, like javadoc, will also be able to automatically discover code for your modules

This leaves off some crucial bits - like how you would get dependencies or run unit tests - but compare it holistically to setting up a multi-module build in Maven. Or Gradle. Or bld. Or whatever.

Leave a Comment