Java Magazine, July/August 2018
ORACLE COM JAVAMAGAZINE JULY AUGUST 2018 54 libraries Similarly use a current version of your build tool In the case of Maven this should at least be version 350 of the application itself and version 370 of the compiler plugin For Gradle use at least version 421 Migration Challenges for Moving to Java 9 Java 9 introduced modules to the ecosystem and with it came many changes Some were caused by the presence of modules These changes caused subtle diferences in Javas behavior and a few could be considered incompatibilities Heres a brief summary of what you can expect and what can be done about it Note that youre unlikely to encounter all of these issues so dont worry too much Failing access to JDK internal APIs The most obvious problem you might encounter is access to internal APIs If your code depends on classes from sun packages or most com sun packages youre bound to see compilation errors like this error package com sun java swing plaf nimbus is not visible import com sun java swing plaf nimbus NimbusLookAndFeel package com sun java swing plaf nimbus is declared in module java desktop which does not export it 1 error The proper fix is to stop using such classes but if you cant do that yet you can make them available at compile time and runtime by using the command line flag add exports If youre accessing JDK internal APIs at runtime via reflection take a look at the flags add opens and illegal access A word of warning regarding command line flags if you use flags to fix any of the problems Im describing here your users will usually need to apply the same flags when running their application with your library That can be a serious inconvenience so try to avoid that if at all possible If you absolutely must use flags make sure you document them well
You must have JavaScript enabled to view digital editions.