Building libraries for multiple Java versions

When migrating applications, we had to deal with the scenario that the dependent libraries might not all be migrated to Java 9. When dealing with libraries, you'll need to tackle the opposite problem. The applications consuming your library may not all be Java 9. You'll have to support Java 8 (or perhaps even older versions of Java in some cases). How do you, as a library author, create library distributions for all those versions? Before Java 9, you used to have two options:

  • You could create separate JARs for each Java version
  • In your library code, you could use reflection to do a feature check. For example, you could reflectively access a platform API that was introduced in Java 8. If it works, ...

Get Modular Programming in Java 9 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.