Running jdeps on your code

The jdeps class dependency analysis tool is not new to Java 9, but perhaps has never been as important to developers with the advent of Java 9. An important step to migrating your applications to Java 9 is to run the jdeps tool to determine the dependencies your applications and its libraries have. The jdeps tool does a great job of suggesting replacements if your code has dependencies on any internal APIs.

The following screenshot shows the options available to you when using the jdeps analyzer:

Let's take a look at an example. Here is a simple Java class called DependencyTest:

    import sun.misc.BASE64Encoder;

public class DependencyTest
{
public static void main(String[] args) throws
InstantiationException, IllegalAccessException
{
BASE64Encoder.class.newInstance();
System.out.println("This Java app ran successfully.");
}
}

Now, let's use javac to compile this class using Java 8:

As you can see, Java 8 successfully compiled the class and the application ran. The compiler did give us a DependencyTest.java:6: warning: BASE64Encoder is internal proprietary API and may be removed in a future release warning. Now, let's see what happens when we try to compile this class using Java 9:

In this case, with Java 9, the compiler gave us two warnings instead of one. The first warning is for the import sun.misc.BASE64Encoder; statement and the second for the BASE64Encoder.class.newInstance(); method call. As you can see, these are just warnings and not errors, so the DependencyTest.java class file is successfully compiled. Next, let's run the application:

Now, we can clearly see that Java 9 will not allow us to run the application. Next, let's run a dependency test using the jdeps analyzer tool. We will use the following command line syntax--jdeps DependencyTest.class:

As you can see, we have three dependencies: java.io, java.lang, and sun.misc. Here we are given the suggestion to replace our sun.misc dependency with rt.jar.