Skip to main content This browser is no longer supported. Show
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Transition from Java 8 to Java 11
In this articleThere's no one-size-fits-all solution to transition code from Java 8 to Java 11. For a non-trivial application, moving from Java 8 to Java 11 can be a significant amount of work. Potential issues include removed API, deprecated packages, use of internal API, changes to class loaders, and changes to garbage collection. In general, the approaches are to try to run on Java 11 without recompiling, or to compile with JDK 11 first. If the goal is to get an application up and running as quickly as possible, just trying to run on Java 11 is often the best approach. For a library, the goal will be to publish an artifact that is compiled and tested with JDK 11. Moving to Java 11 is worth the effort. New features have been added and enhancements have been made since Java 8. These features and enhancements improve startup, performance, memory usage, and provide better integration with containers. And there are additions and modifications to API that improve developer productivity. This document touches on tools to inspect code. It also covers issues that you may run into and recommendations for resolving them. You should also consult other guides, such as the Oracle JDK Migration Guide. How to make existing code modular is not covered here. Java 11 has two tools, jdeprscan and jdeps, that are useful for sniffing out potential issues. These tools can be run against existing class or jar files. You can assess the transition effort without having to recompile. jdeprscan looks for use of deprecated or removed API. Use of deprecated API is not a blocking issue, but is something to look into. Is there an updated jar file? Do you need to log an issue to address the use of deprecated API? Use of removed API is a blocking issue that has to be addressed before you try to run on Java 11. jdeps, which is a Java class dependency analyzer. When used with the There are jdeps and jdeprscan plugins for both Gradle and Maven. We recommend adding these tools to your build scripts. The Java compiler itself, javac, is another tool in your toolbox. The warnings and errors you get from jdeprscan and jdeps will come out of the compiler. The advantage of using jdeprscan and jdeps is that you can run these tools over existing jars and class files, including third-party libraries. What jdeprscan and jdeps cannot do is warn about the use of reflection to access encapsulated API. Reflective access is checked at runtime. Ultimately, you have to run the code on Java 11 to know with certainty. Using jdeprscanThe easiest way to use jdeprscan is to give it a jar file from an existing build. You can also give it a directory, such as the compiler output directory, or an individual class name. Use the
The jdeprscan tool generates an error message if it has trouble resolving a dependent class. For example,
This output tells us that the Run Using jdepsUse jdeps, with the
The output gives some good advice on eliminating use of JDK internal API! Where possible, the replacement API is suggested. The name of the module where the package is encapsulated is given in the parentheses. The module name can be used with The use of sun.misc.BASE64Encoder or sun.misc.BASE64Decoder will result in a java.lang.NoClassDefFoundError in Java 11. Code that uses these APIs has to be modified to use java.util.Base64. Try to eliminate the use of any API coming from the module jdk.unsupported. API from this module will reference JDK Enhancement Proposal (JEP) 260 as a suggested replacement. In a nutshell, JEP 260 says that the use of internal API will be supported until replacement API is available. Even though your code may use JDK internal API, it will continue to run, for a while at least. Do take a look at JEP 260 since it does point to replacements for some internal API. variable handles can be used in place of some sun.misc.Unsafe API, for example. jdeps can do more than just scan for use of JDK internals. It is a useful tool for analyzing dependencies and for generating a module-info files. Take a look at the documentation for more. Using javacCompiling with JDK 11 will require updates to build scripts, tools, test frameworks, and included libraries. Use the Libraries can consider packaging as a multi-release jar file. Multi-release jar files allow you to support both Java 8 and Java 11 runtimes from the same jar file. They do add complexity to the build. How to build multi-release jars is beyond the scope of this document. Running on Java 11Most applications should run on Java 11 without modification. The first thing to try is to run on Java 11 without recompiling the code. The point of just running is to see what warnings and errors come out of the execution. This approach gets an Most of the problems you may encounter can be resolved without having
to recompile code. If an issue has to be fixed in the code, then make the fix but continue to compile with JDK 8. If possible, work on getting the application to run with Check command line optionsBefore running on Java 11, do a quick scan of the command-line options. Options that have been removed will cause the Java Virtual Machine (JVM) to exit. This check is especially important if you use GC logging options since they have changed drastically from Java 8. The JaCoLine tool is a good one to use to detect problems with the command line options. Check third-party librariesA potential source of trouble is third-party libraries that you don't control. You can proactively update third-party libraries to more recent versions. Or you can see what falls out of running the application and only update those libraries that are necessary. The problem with updating all libraries to a recent version is that it makes it harder to find root cause if there is some error in the application. Did the error happen because of some updated library? Or was the error caused by some change in the runtime? The problem with updating only what's necessary is that it may take several iterations to resolve. The recommendation here is to make as few changes as possible and to update third-party libraries as a separate effort. If you do update a third-party library, more often than not you will want the latest-and-greatest version that is compatible with Java 11. Depending on how far behind your current version is, you may want to take a more cautious approach and upgrade to the first Java 9+ compatible version. In addition to looking at release notes, you can use jdeps and jdeprscan to assess the jar file. Also, the OpenJDK Quality Group maintains a Quality Outreach wiki page that lists the status of testing of many Free Open Source Software (FOSS) projects against versions of OpenJDK. Explicitly set garbage collectionThe Parallel garbage collector (Parallel GC) is the default GC in Java 8. If the application is using the default, then the GC should be explicitly set with
the command-line option Explicitly set default optionsIf running on the HotSpot VM, setting the command line option Setting the command line option ClassLoader cautionsIn Java 8, you can cast the system class loader to a In Java 11, the boot class loader only loads core modules. If you create a class loader with a null parent, it may not find all platform classes. In Java 11, you need to pass Locale data changesThe default source for locale data in Java 11 was changed with JEP 252 to the Unicode Consortium's Common Locale Data Repository. This may have an impact on localized formatting. Set the system property Potential issuesHere are some of the common issues you might come across. Follow the links for more details about these issues.
Unrecognized optionsIf a command-line option has been removed, the application will print In general, options that were removed have no replacement and the only recourse is to remove the option from the command line. The exception is options for garbage collection logging. GC logging was reimplemented in Java 9 to use the unified JVM logging framework. Refer to "Table 2-2 Mapping Legacy Garbage Collection Logging Flags to the Xlog Configuration" in the section Enable Logging with the JVM Unified Logging Framework of the Java SE 11 Tools Reference. VM warningsUse of deprecated options will produce a warning. An option is deprecated when it has been replaced or is no longer useful. As with removed options, these options should be removed from the command line. The warning The web page VM Options Explorer provides an exhaustive list of options that have been added to or removed from Java since JDK 7. Error: Could not create the Java Virtual MachineThis error message is printed when the JVM encounters an unrecognized option. WARNING: An illegal reflective access operation has occurredWhen Java code uses reflection to access JDK-internal API, the runtime will issue an illegal reflective access warning.
What this means is that a module has not exported the package that is being accessed through reflection. The package is encapsulated in the module and is, basically, internal API. The warning can be ignored as a first effort to getting up and running on Java 11. The Java 11 runtime permits the reflective access so that legacy code can continue to work. To address this warning, look for updated code that does not make use of the internal API.
If the issue cannot be resolved with updated code, either the The The
The warning in the example
above is issued because the java.lang.reflect.InaccessibleObjectExceptionThis exception indicates that you are trying to call
java.lang.NoClassDefFoundErrorNoClassDefFoundError is most likely caused by a split package, or by referencing removed modules. NoClassDefFoundError caused by split-packagesA split package is when a package is found in more than one library. The symptom of a split-package problem is that a class you know to be on the class-path is not found. This issue will only occur when using the module-path. The Java module system optimizes class lookup by restricting a package to one named module. The runtime gives preference to the module-path over the
class-path when doing a class lookup. If a package is split between a module and the class-path, only the module is used to do the class lookup. This can lead to An easy way to check for a split package is to plug your module path and class path into jdeps and use the path to your application class files as the <path>. If there is a split package, jdeps
will print out a warning: This issue can be resolved by using NoClassDefFoundError caused by using Java EE or CORBA modulesIf the application runs on Java 8 but throws a To resolve the issue, add a runtime dependency to your project. -Xbootclasspath/p is no longer a supported optionSupport for What --patch-module does, in effect, is insert the patch module into the module system's class lookup. The module system will grab the class from the patch module first. This is the same effect as pre-pending the bootclasspath in Java 8. UnsupportedClassVersionErrorThis exception means that you are trying to run code that was compiled with a later version of Java on an earlier version of Java. For example, you are running on Java 11 with a jar that was compiled with JDK 13.
Next stepsOnce the application runs on Java 11, consider moving libraries off the class-path and onto the module-path. Look for updated versions of the libraries your application depends on. Choose modular libraries, if available. Use the module-path as much as possible, even if you don't plan on using modules in your application. Using the module-path has better performance for class loading than the class-path does. Which type of app would most likely not be found in a productivity suite?Which type of app would most likely NOT be found included in a productivity suite? Ans: web browser 4. To run a productivity app with most complete and advanced capabilities, you would most likely .
Which of the following is not an option for formatting text?Detailed Solution. The correct answer is Alignment. Alignment is NOT a character formatting option in Ms-Word. Microsoft Word provides for aligning text in paragraphs in four different ways – left alignment, right alignment, centre alignment and justified.
What contains the instructions your computer device needs to run program and app?An operating system is responsible for identifying, configuring, and providing applications with common access to underlying computer hardware devices.
What type of software manages the complete operation of a computer?An operating system is software that supports and manages all the programs and applications used by a computer or mobile device. An operating system uses a graphic user interface (GUI), a combination of graphics and text, that allows you to interact with the computer or device.
|