This is a sandbox app created to test out Java 9' Project Jigsaw with Maven functionality.
For Project Jigsaw, without maven, check this tutorial: http://openjdk.java.net/projects/jigsaw/quick-start
For reference, I have also added Java 8 app to do the similar thing.
I have used simple Java Reflection API and not the ServiceLoader since I wanted to pass parameters and not use default constructors or Abstract Factories.
- Created an
interface Shape - Created two implementations
class Circleandclass Squareofinterface Shape. Main Appshould havecompile-timedependency oninterface Shape, butruntimedependency on implementations.
- API
- Module which has
interface Shapeand default implementationclass Square.
- Module which has
- IMPL
- Module has
compile-timedependency on API. - This module has
class Circlewhich has custom implementation ofinterface Shape.
- Module has
- APP
- This module has the
Mainclass. - It will use
class ShapeFactoryin API, which will create objects ofCircleandSquareusing Java Reflection API (wanted to keep things simple and avoid any dependency injection libs/frameworks). - Try to uncomment the lines which are trying to use
CircleandSquareclasses at compile-time. It should give a compile-time error.
- This module has the
[APP] ---- (compile-time) ----> [API] <---- (compile-time) ---- [IMPL]
\ ^
\_________________________ (runtime) _______________________/
mvn clean package
Add this in ~/.m2/toolchains.xml
<?xml version="1.0"?>
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<version>1.9</version>
<vendor>oracle</vendor>
</provides>
<configuration>
<jdkHome>/path/to/java-9/home</jdkHome>
</configuration>
</toolchain>
</toolchains>
Java9's JPMS do not work on IntelliJ 2017.2.*
You need IntelliJ with version 2017.3 or later.
You may need to explicitly change the module SDKs to Java9.