Problems in upgrading from Java 8 to Java 11

Jiedao jdon 2021-05-04 12:37:27
problems upgrading java java


from Java 8 Migrate to Java 11 More difficult than most upgrades . Here are some considerations for this process .

modular

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 .

summary

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 .

版权声明
本文为[Jiedao jdon]所创,转载请带上原文链接,感谢
https://javamana.com/2021/05/20210504123224199O.html

  1. Java 11已经不再完全免费,不要陷入Oracle的Java 11陷阱
  2. Vue.js比jQuery更容易学习
  3. 启动/删除Docker容器时出现问题 - 如何修复
  4. eclipse run on server时出现了错误信息.求急!!
  5. 请教高手一个关于lunce的问题:java.io.IOException: Cannot rename ...\segments.new
  6. Java 11 is no longer completely free. Don't fall into the Java 11 trap of Oracle
  7. Vue. JS is easier to learn than jQuery
  8. Problem starting / deleting docker container - how to fix it
  9. There is an error message in eclipse run on server!!
  10. Ask a question about lunce: java.io.ioexception: cannot rename... \ segments.new
  11. 从零搭建Spring Boot脚手架(2):集成mybatis
  12. 从零搭建Spring Boot脚手架(4):手写Mybatis通用Mapper
  13. 只知道java反射,宁知道内省吗?
  14. Build spring boot scaffold from scratch (2): integrate mybatis
  15. Build spring boot scaffold from scratch (4): handwritten mybatis general mapper
  16. Do you prefer introspection to reflection?
  17. ASP调用SDK微信分享好友、朋友圈
  18. ASP calls SDK wechat to share friends and circle of friends
  19. BAT 必问的 MySQL 面试题你都会吗?
  20. Do you know all the MySQL interview questions that bat must ask?
  21. ASP调用SDK微信分享好友、朋友圈
  22. ASP calls SDK wechat to share friends and circle of friends
  23. SpringCloud(六)Bus消息总线
  24. 详解JavaScript中的正则表达式
  25. Springcloud (6) bus message bus
  26. Explain regular expressions in JavaScript
  27. Java 响应式关系数据库连接了解一下
  28. Java14它真的来了, 真是尾气都吃不到了
  29. 视频:使用Docker搭建RabbitMQ环境
  30. Java responsive relational database connection
  31. Java14 it's really coming. I can't eat the exhaust
  32. Video: building rabbitmq environment with docker
  33. SpringCloud(六)Bus消息总线
  34. 详解JavaScript中的正则表达式
  35. Springcloud (6) bus message bus
  36. Explain regular expressions in JavaScript
  37. Docker实战:用docker-compose搭建Laravel开发环境
  38. Docker: building laravel development environment with docker compose
  39. 求助,JAVA如何获取系统当前所有进程
  40. 有人用过JMeter或用HttpUnit写过测试吗????
  41. Help, Java how to get all the current processes of the system
  42. Has anyone ever used JMeter or written tests in httpUnit????
  43. Living in a mountain village in late spring
  44. Partridge day, spring of HKUST
  45. JavaScript异步编程4——Promise错误处理
  46. 海康摄像SDK开发笔记(一):海康威视网络摄像头SDK介绍与模块功能
  47. JavaScript asynchronous programming 4 -- promise error handling
  48. Haikang video SDK development notes (1): introduction and module functions of Hikvision webcam SDK
  49. JOP:用于FPGA的嵌入式实时系统中的Java优化处理器内核
  50. Spring Boot源码:使用MongoDB MongoTemplate公开REST在几分钟内实现CRUD功能
  51. Spring Boot应用程序事件教程 - reflectoring
  52. 带有Resilience4j断路器的Spring云网关 - rome
  53. 经验分享:Apache Kafka的缺点与陷阱 - Emil Koutanov
  54. 通过Spring Boot Webflux实现Reactor Kafka
  55. 从Java 8升级到Java 11应该注意的问题
  56. Jop: Java optimized processor core for FPGA embedded real time system
  57. Spring boot source code: use mongodb mongotemplate to open rest to realize crud function in a few minutes
  58. Spring boot application event tutorial - reflecting
  59. Spring cloud gateway with resilience4j circuit breaker - ROM
  60. Experience sharing: shortcomings and pitfalls of Apache Kafka - Emil koutanov