Skip to content

Latest commit

 

History

History

03_ServiceMonitor_migration_to_java_9

ServiceMonitor - Migration


Thanks to Nicolai Parlog for letting us use his original migration example into this exercise, among many other good things, also author of the book Java 9 Module System.


An example application for my book The Java 9 Module System. The Service Monitor is an application that observes a hypothetical network of microservices by

  • contacting individual services
  • collecting and aggregating diagnostic data into statistics
  • persisting statistics
  • making statistics available via REST

It is split into a number of modules that focus on specific concerns. Each module has its own directory that contains the known folder structure, e.g. src/main/java.

It was developed as a Java 8 application and now needs to be made compatible with Java 9 and then be modularized.

Build and Execution

In the project's root folder:

  • to build: mvn clean install
  • to run: java -cp 'monitor/target/libs/*':'monitor/target/main-1.0-SNAPSHOT.jar' monitor.Main
  • to contact REST endpoints:
    • curl http://localhost:4567/stats/json
    • curl http://localhost:4567/stats/json64 | base64 -d
    • curl http://localhost:4567/stats/xml

Troubles

Migration

  • internal BASE64Encoder is gone ~> use Base64.getEncoder instead
  • JAXB API is not present ~> add java.xml.bind
  • Common annotations are not present ~> add java.xml.ws.annotations
  • split package: javax.annotation between java.xml.ws.annotations and jsr-305 ~> patch java.xml.ws.annotations
  • old version of Mockito causes warnings ~> update to newer version
  • application class loader is no longer a URLClassLoader

Cheatsheet

To help and give a bit more hints during the refactoring process refer to our migration cheatsheet.

Warning: but this might just take away all the fun learning.