JavaInspect - usage from commandline
Table of Contents
1. Commandline arguments
- -j (existing files)…
- JAR file(s) to render.
- -c (existing directories)…
- Classpath directories
- -n (string)
- Graph name. (default: "graph")
- –debug
- Show debug info.
- -h, –help
- Show commandline usage help.
- -k
- Keep dot file.
- -ho
- Hide orphaned classes.
- -w (one to many strings)…
- Whitelist glob(s).
- -b (one to many strings)…
- Blacklist glob(s).
- -r (one to many strings)…
- root class(es).
- -d (existing directory)
- Target directory. Default is current directory.
- -t (options: png, svg)
- Target image type. Default is: svg.
2. Specifying classes to render
A typical Java application has immense complexity. Beyond code written by the project's developers, there are typically many frameworks, libraries, and the Java standard library.
Since JavaInspect uses reflection, it cannot easily distinguish between these sources. Usually you want to visualize only the code developed for your project, excluding frameworks like Spring. If you visualize all classes reachable from your project, the graph becomes huge and incomprehensible.
JavaInspect can analyze compiled Java classes in two modes:
- Provide JAR files using the -j option.
- Provide filesystem directories as classpath roots using the -c option.
JavaInspect uses the following algorithm to add classes to the graph:
- All classes found in JAR files are added to the graph by default.
- Classes found in filesystem directories are not added by default unless explicitly referenced. (TODO: for consistency, these should also be added by default)
- If a whitelist is specified (-w option), classes not matching the whitelist patterns are removed from the graph.
- If a blacklist is specified (-b option), classes matching the blacklist patterns are removed from the graph.
- Root classes can be specified using the -r option. JavaInspect recursively discovers all classes referenced by root classes and adds them to the graph.
3. Examples
Visualize a Java JAR file with all classes, hiding orphaned classes:
javainspect \ -j target/sixth-3d-*-SNAPSHOT.jar \ -d doc/graphs/ \ -n "All classes" \ -t png -ho
Visualize a Java JAR file with a whitelist filter, hiding orphaned classes:
javainspect \ -j target/sixth-3d-*-SNAPSHOT.jar \ -d doc/graphs/ \ -n "GUI" \ -t png \ -w "eu.svjatoslav.sixth.e3d.gui.*" \ -ho