Modularity =
←Older revision | Revision as of 06:12, 16 February 2021 | ||
Line 43: | Line 43: | ||
Our application has to be composed from both [[JAR]] files: ''app-jdk8.jar'' and ''app-jdk11.jar''. The entrypoint has to be in the ''app-jdk8.jar'' and it has to do something reasonable by its own when executed on [[JDK]]8. The use of '''ServiceLoader().load(BetterHandler.class)''' is going to return no ''JDK11EnhancedHandler'' (possibly yielding some {{JDK|java/lang|LinkageError}}) and as such the fallback code is executed. However when running on [[JDK11]] the ''JDK11EnhancedHandler'' is instantiated and can easily access the [[JDK11]] specific functionality. | Our application has to be composed from both [[JAR]] files: ''app-jdk8.jar'' and ''app-jdk11.jar''. The entrypoint has to be in the ''app-jdk8.jar'' and it has to do something reasonable by its own when executed on [[JDK]]8. The use of '''ServiceLoader().load(BetterHandler.class)''' is going to return no ''JDK11EnhancedHandler'' (possibly yielding some {{JDK|java/lang|LinkageError}}) and as such the fallback code is executed. However when running on [[JDK11]] the ''JDK11EnhancedHandler'' is instantiated and can easily access the [[JDK11]] specific functionality. | ||
- | === [[Modularity]] | + | === [[Modularity]] === |
Both [[OSGi]] as well as [[NetBeans Runtime Container]] help bring this setup to even a better level. They allow one to specify in the ''app-jdk11.jar'' manifest that the [[module]] requires [[JDK11]]. E.g. when running on [[JDK]]8 the ''JDK11EnhancedHandler'' class isn't going to even be available on the "classpath". That is going to prevent any {{JDK|java/lang|LinkageError}} and just return ''null'' when the implementation of ''ServiceLoader().load(BetterHandler.class)'' is requested. | Both [[OSGi]] as well as [[NetBeans Runtime Container]] help bring this setup to even a better level. They allow one to specify in the ''app-jdk11.jar'' manifest that the [[module]] requires [[JDK11]]. E.g. when running on [[JDK]]8 the ''JDK11EnhancedHandler'' class isn't going to even be available on the "classpath". That is going to prevent any {{JDK|java/lang|LinkageError}} and just return ''null'' when the implementation of ''ServiceLoader().load(BetterHandler.class)'' is requested. |