5. New Java tools

Java 8 comes with new set of command line tools. In this section we are going to look over most interesting of them.

5.1. Nashorn engine: jjs

jjs is a command line based standalone Nashorn engine. It accepts a list of JavaScript source code files as arguments and runs them. For example, let us create a file func.js with following content:

  1. function f() {
  2. return 1;
  3. };
  4.  
  5. print( f() + 1 );

To execute this fie from command, let us pass it as an argument to jjs:

  1. jjs func.js

The output on the console will be:

  1. 2

For more details please refer to official documentation.

5.2. Class dependency analyzer: jdeps

jdeps is a really great command line tool. It shows the package-level or class-level dependencies of Java class files. It accepts .class file, a directory, or JAR file as an input. By default, jdeps outputs the dependencies to the system output (console).

As an example, let us take a look on dependencies report for the popular Spring Framework library. To make example short, let us analyze only one JAR file: org.springframework.core-3.0.5.RELEASE.jar.

  1. jdeps org.springframework.core-3.0.5.RELEASE.jar

This command outputs quite a lot so we are going to look on the part of it. The dependencies are grouped by packages. If dependency is not available on a classpath, it is shown as not found.

  1. org.springframework.core-3.0.5.RELEASE.jar -> C:\Program Files\Java\jdk1.8.0\jre\lib\rt.jar
  2. org.springframework.core (org.springframework.core-3.0.5.RELEASE.jar)
  3. -> java.io
  4. -> java.lang
  5. -> java.lang.annotation
  6. -> java.lang.ref
  7. -> java.lang.reflect
  8. -> java.util
  9. -> java.util.concurrent
  10. -> org.apache.commons.logging not found
  11. -> org.springframework.asm not found
  12. -> org.springframework.asm.commons not found
  13. org.springframework.core.annotation (org.springframework.core-3.0.5.RELEASE.jar)
  14. -> java.lang
  15. -> java.lang.annotation
  16. -> java.lang.reflect
  17. -> java.util

For more details please refer to official documentation.