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:
- function f() {
- return 1;
- };
- print( f() + 1 );
To execute this fie from command, let us pass it as an argument to jjs:
- jjs func.js
The output on the console will be:
- 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.
- 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.
- org.springframework.core-3.0.5.RELEASE.jar -> C:\Program Files\Java\jdk1.8.0\jre\lib\rt.jar
- org.springframework.core (org.springframework.core-3.0.5.RELEASE.jar)
- -> java.io
- -> java.lang
- -> java.lang.annotation
- -> java.lang.ref
- -> java.lang.reflect
- -> java.util
- -> java.util.concurrent
- -> org.apache.commons.logging not found
- -> org.springframework.asm not found
- -> org.springframework.asm.commons not found
- org.springframework.core.annotation (org.springframework.core-3.0.5.RELEASE.jar)
- -> java.lang
- -> java.lang.annotation
- -> java.lang.reflect
- -> java.util
For more details please refer to official documentation.