The jdeps tool

The Java Dependency Analysis Tool (jdeps) is a utility that can statically examine your application and library classes to identify if there are any uses of the JDK internal APIs that no longer work with Java 9. You can run jdeps on your compiled class files or JARs, and have it list out all such references. For each reference, jdeps will highlight usages of internal types that are no longer available for your code to use. It even suggests replacement APIs if they are available.

The command syntax looks like this:

$ jdeps -jdkinternals <jar-files>  

If you have a bunch of classes compiled and you want to run jdeps on them, you can even provide a classpath parameter:

$ jdeps -jdkinternals -cp <class-paths>  

Let's try this with the 02-non-standard-api project. We've already compiled the project (albeit with warnings) with the Java 8 compiler, and the classes now exist in the out directory. Running jdeps on them yields the following output:

sun.misc.BASE64Encoder is indicated as a JDK removed internal API while sun.util.calendar.CalendarUtils is indicated as a JDK internal API from java.base. In the case of BASE64Encoder, the tool provides a helpful suggestion to use an alternative API (java.util.Base64) that has been available in Java since version 1.8.

jdeps can also be run on JARs as previously mentioned. If we were to run the tool on the included 01-app-migration project for example, we'll get no output. Which is a good thing because that means there are no JDK internals being used, and the JAR is good to use for Java 9:

$ jdeps -jdkinternals commons-collections4-4.1.jar  
jdeps is a static code analysis tool, with emphasis on the word static. It looks at the code to identify illegal API use. It cannot identify dynamic runtime use through reflection, for example. Thus, there is a chance that jdeps gives you the all-clear for a code base, but when you run it, you might still end up with an IllegalAccessException because the code uses reflection to access an internal type that's no longer available.

To summarize, jdeps -jdkinternals is a great tool to use to check your pre-compiled application and library classes and verify any incompatibilities with Java 9. It is especially helpful that the tool recommends alternative options to use when possible.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.200.71