stay Java 9 in Java Introduced one of the biggest changes in history It's a module , but ：
You don't have to modularize your own code to upgrade to Java 11.
in the majority of cases , Put it in the classpath classpath The code on can continue in Java 9 And later versions are effectively found and run , But if the module is placed on the classpath, it will be ignored , This is very bad for library package publishers , But it's a good thing for application developers .
therefore , The upgrade to the Java 11 Try not to modularize as much as possible , And turn your application into Java Modules should wait for the moment , It's only a few years after the large-scale open source dependency library package really adopts modularization , Now? , Trying to modularize is painful , Because your dependency packages are rarely modular .
（ If the main reason for modularization is due to the use of jlink It can shrink JDK Size , And there's no need for modularity to achieve this - Just use Maven Create a jar- with-dependencies, among module-info Not configured require, Not configured export( no-requires and no-exports ).
Deleted JDK Part of
JDK About Java EE and Corba Part of it has been deleted , They are no longer suitable for JDK, Or it can be maintained elsewhere .
If you use Corba, So there's almost no one to help you , however , If you use Java EE modular , So in most cases , Fixing deleted code should be simple . Just add the appropriate Maven that will do .
stay Java On the client side , Has deleted Java WebStart , Alternatives will be more tricky , Please consider using Getdown or Update4J.
Insecurity and friends
these years , Sun and Oracle I've been telling developers not to use sun.misc.Unsafe And other cutting-edge JDK API. For a long time ,Java 9 I'm going to delete these , But it never actually happened .
But in Java 11, Limited first time access API when , You may be warned , This warning is printed only once . It's a useful reminder , Your code or dependencies are doing something “ naughty ” Things about , It needs to be fixed at some point .
You'll also find Java 11 There are many specially designed new API, To avoid using Unsafe Human needs , If you're using “ illegal ”API, Please give priority to these new API, for example , Base64, MethodHandles.privateLookupIn, MethodHandles.Lookup.defineClass, StackWalker and Variable Handles.
Tools and Libraries
The combination of modularity and the new six-month release cycle has a real impact on the use of tools and libraries by developers , Some projects have been able to keep up with , Some people are trying to , Some people fail .
Upgrade to Java 11 when , The key task is to update all dependencies to the latest version , If from Java 9 No new versions of these dependencies have been released since their inception , Then these dependencies may require additional attention or testing , Make sure you also update IDE.
however , Not only do you need to update the application's dependencies ,Maven So it is with , majority Maven The plug-in has changed the major version to v3.x, take Maven Upgrade itself to v3.5.4 It's also helpful .
It is sad , The core maven The team is small , So there are still some problems to be solved , however , If your Maven It's very reasonable and simple to build , Well, usually it's ok . But please pay attention to , Remove the plug-in from the v2.x Upgrade to v3.x You may need to change the configuration , Not just associated with modules . for example ,Maven Javadoc The plug-in has renamed the argLine attribute .
A key point to note is Maven The way you operate with modules , When Maven Compiler or surefire The plug-in found a modular jar file （ With module-info.class） when , It can put the jar On the module path instead of the class path , therefore , Even if you might plan to run your application only on classpath ,Maven It's possible to partially compile and test the code on the classpath , The other part compiles the code on the module path , In the present , There's nothing that can fix this .
Sometimes your build needs a bigger change . for example , Need to put Findbugs Change to SpotBugs, And will Cobertura Change it to JaCoCo.
These build changes may take some time .
When I finish the migration , My conclusion is that the pain mainly lies in maintenance and Java 8 The compatibility of , Make the application all to Java 11 It should be simpler , Because there's no need to talk to Java 8 Keep in contact .