Disclaimer: do not follow the steps below literally, in case of issues try to debug. If you think it is an issue, report back in the feedback form or ask on the IRC channel.
Enjoy the modularisation journey!
-
Pre-modularisation detective work
jdeps -s -R -cp 'monitor/target/libs/*' monitor/target/main-1.0-SNAPSHOT.jarjdepstells us about the split package we encountered during the migration processjdeps -s -R -include 'monitor.*' -cp 'monitor/target/libs/*' monitor/target/Machine-1.0-SNAPSHOT.jarunnamed modules have a 'not found' against them - these are our modules that are not Java 9 modules yet
jdeps -s -R -include 'monitor.*' --dot-output . -cp 'monitor/target/libs/*' monitor/target/Machine-1.0-SNAPSHOT.jarcreates a dot output of the module graph
Use the
jdepsoutput to navigate through your module graph and learn about the dependencies between the modules. -
Create modules
- create
monitor.utils-
go to module in the IDE
- In IntelliJ, Add the folder ... as a module via File > New > Module from Existing source (check search project recursively, and click on Next till you navigate till Finish, IntelliJ detects it to be a Java project)
-
Set the SDK and language level of the project and modules to Java 9
-
Go to
monitor.utils>src/main/java, right mouse click > New > module-info.java, name the module monitor.utils -
run
./compile.shfrom the project root -
run
./run.shfrom the project root -
put the jar onto the module-path in the
compile.shfor monitor.utils -
run
./compile.shfrom the project root -
we get errors:
monitor.rest/src/main/java/monitor/rest/MonitorServer.java:16: error: package monitor.utils is not visible import static monitor.utils.Utils.toBase64; ^ -
fix it by making the monitor.utils available in to monitor.rest during compile time (amend
compile.shfor it, hint: --add-modules) -
but also add it to monitor section in the compile.sh
-
run
./compile.shfrom the project root -
issue fixed
-
run
./run.shfrom the project root -
we get an error:
Exception in thread "main" java.lang.NoClassDefFoundError: monitor/utils/Utils -
add the newly created module to the
run.sh
-
- now make monitor.observer modular
- create the
module-infoand make the respective package(s) available - then make monitor.observer.alpha, monitor.observer.beta modular
- create the
module-infofor both and make the respective package(s) available, also define the dependency (check source to find out) - make the respective changes to the
compile.sh(find out the modular dependencies) - resolve the compiler failures
- run
compile.shagain - make the respective changes to the
run.sh(use the modular dependencies) - resolve the runtime failures
- run
run.shagain
- create the
- now make monitor.statistics modular
- create the
module-infoand make the respective package(s) available, also define the dependency (check source to find out) - make the respective changes to the
compile.sh(find out the modular dependencies) - resolve the compiler failures
- run
compile.shagain - make the respective changes to the
run.sh(use the modular dependencies) - resolve the runtime failures
- run
run.shagain
- create the
- now make
monitor.restmodular-
create the
module-infoand make the respective package(s) available, also define the dependency (check source to find out) -
define the dependencies on the automatic (unnamed) module
-
make the respective changes to the
compile.sh(find out the modular dependencies) -
resolve the compiler failures
-
you will need to make sure the automatic (unnamed) modules from the class path to the module path (amend compile.sh)
-
run
compile.shagain -
make the respective changes to the
run.sh(use the modular dependencies) -
resolve the runtime failures
-
run
run.shagain -
run
curl http://localhost:4567/stats/xml -
this should fail:
javax.xml.bind.JAXBException: Package monitor.rest with JAXB class monitor.rest.StatisticsEntity defined in a module monitor.rest must be open to at least java.xml.bind module. -
Amend the
module-infoto allow (opens) javax.xml.bind to reflectively see monitor.rest -
run
compile.shagain -
run
run.shagain -
run
curl http://localhost:4567/stats/xml -
Continue modularising the remaining maven module(s)
-
- create
If all of this does not make sense, watch the second half of Nicolai Parlog's video on From Jar hell and Back.