Java 为类依赖生成图数据的工具
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19807372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
tool to generate graph data for class dependencies
提问by Rostislav Matl
Is there some tool that is able to analyze Java source files, construct a graph from it and provide the graph's data in some standard / understandable format?
是否有一些工具能够分析 Java 源文件、从中构建图形并以某种标准/可理解的格式提供图形数据?
It definitively does not need to have GUI, I'd prefer a command line thing so I can process the output by various tools (for segmentation, visualization,...).
它绝对不需要 GUI,我更喜欢命令行的东西,这样我就可以通过各种工具处理输出(用于分割、可视化……)。
回答by Jason Lowenthal
I'm not certain about command line tools, but I like using ObjectAid for reverse engineering into class diagrams:
我不确定命令行工具,但我喜欢使用 ObjectAid 逆向工程到类图中:
You can easily add any class with it's relationships to an ObjectAid graph. It saves the file in an XML format with the ucls extension. Here's a sample:
您可以轻松地将任何类及其关系添加到 ObjectAid 图。它以带有 ucls 扩展名的 XML 格式保存文件。这是一个示例:
<?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.1.4" icons="true"
always-add-relationships="true" generalizations="true" realizations="true"
associations="true" dependencies="true" nesting-relationships="true">
<class id="1" language="java"
name="my.classpath.common.controllers.AuthenticationInterceptor"
project="MyProject"
file="/SpecialPath/common/controllers/AuthenticationInterceptor.java"
binary="false" corner="BOTTOM_RIGHT">
<position height="205" width="355" x="2222" y="37" />
<display autosize="true" stereotype="true" package="true"
initial-value="false" signature="true" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true"
private="true" static="true" />
<operations public="true" package="true" protected="true"
private="true" static="true" />
</display>
</class>
<class id="2" language="java"
name="my.classpath.common.domain.CompanyAssignmentLocation" project="MyProject"
file="/SpecialPath/common/domain/CompanyAssignmentLocation.java"
binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="856" y="399" />
<display autosize="true" stereotype="true" package="true"
initial-value="false" signature="true" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true"
private="true" static="true" />
<operations public="true" package="true" protected="true"
private="true" static="true" />
</display>
</class>
<class id="3" language="java"
name="my.classpath.common.domain.LocationsSpreadsheetReader" project="MyProject"
file="/SpecialPath/common/domain/LocationsSpreadsheetReader.java"
binary="false" corner="BOTTOM_RIGHT">
<position height="115" width="348" x="680" y="37" />
<display autosize="true" stereotype="true" package="true"
initial-value="false" signature="true" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true"
private="true" static="true" />
<operations public="true" package="true" protected="true"
private="true" static="true" />
</display>
</class>
<class id="4" language="java" name="my.classpath.common.domain.Stock"
project="MyProject" file="/SpecialPath/common/domain/Stock.java"
binary="false" corner="BOTTOM_RIGHT">
<position height="439" width="210" x="430" y="37" />
<display autosize="true" stereotype="true" package="true"
initial-value="false" signature="true" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true"
private="true" static="true" />
<operations public="true" package="true" protected="true"
private="true" static="true" />
</display>
</class>
<class id="5" language="java" name="my.classpath.common.util.FilesUtil"
project="MyProject" file="/SpecialPath/common/util/FilesUtil.java"
binary="false" corner="BOTTOM_RIGHT">
<position height="277" width="218" x="1409" y="37" />
<display autosize="true" stereotype="true" package="true"
initial-value="false" signature="true" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true"
private="true" static="true" />
<operations public="true" package="true" protected="true"
private="true" static="true" />
</display>
</class>
<class id="6" language="java" name="my.classpath.common.util.MyProjectUtil"
project="MyProject" file="/SpecialPath/common/util/MyProjectUtil.java"
binary="false" corner="BOTTOM_RIGHT">
<position height="439" width="349" x="41" y="37" />
<display autosize="true" stereotype="true" package="true"
initial-value="false" signature="true" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true"
private="true" static="true" />
<operations public="true" package="true" protected="true"
private="true" static="true" />
</display>
</class>
<class id="7" language="java" name="my.classpath.common.util.SpringUtil"
project="MyProject" file="/SpecialPath/common/util/SpringUtil.java"
binary="false" corner="BOTTOM_RIGHT">
<position height="133" width="246" x="1936" y="37" />
<display autosize="true" stereotype="true" package="true"
initial-value="false" signature="true" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true"
private="true" static="true" />
<operations public="true" package="true" protected="true"
private="true" static="true" />
</display>
</class>
<class id="8" language="java"
name="my.classpath.common.util.MyProjectUserUtil" project="MyProject"
file="/SpecialPath/common/util/MyProjectUserUtil.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="133" width="229" x="1667" y="37" />
<display autosize="true" stereotype="true" package="true"
initial-value="false" signature="true" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true"
private="true" static="true" />
<operations public="true" package="true" protected="true"
private="true" static="true" />
</display>
</class>
<class id="9" language="java" name="my.classpath.common.util.UnitConversion"
project="MyProject" file="/SpecialPath/common/util/UnitConversion.java"
binary="false" corner="BOTTOM_RIGHT">
<position height="151" width="301" x="1068" y="37" />
<display autosize="true" stereotype="true" package="true"
initial-value="false" signature="true" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true"
private="true" static="true" />
<operations public="true" package="true" protected="true"
private="true" static="true" />
</display>
</class>
<dependency id="10">
<end type="SOURCE" refId="3" />
<end type="TARGET" refId="2" />
</dependency>
<classifier-display autosize="true" stereotype="true"
package="true" initial-value="false" signature="true" accessors="true"
visibility="true">
<attributes public="true" package="true" protected="true"
private="true" static="true" />
<operations public="true" package="true" protected="true"
private="true" static="true" />
</classifier-display>
<association-display labels="true" multiplicity="true" />
</class-diagram>
You can also use PlantUML, but it's better for forward engineering than reverse engineering:
您也可以使用 PlantUML,但它更适合正向工程而不是反向工程:
http://plantuml.sourceforge.net/
http://plantuml.sourceforge.net/
PlantUML has its own unique syntax that you can get source for, too - but it's not nearly as easy to pull together as ObjectAid
PlantUML 有自己独特的语法,您也可以获得源代码 - 但它并不像 ObjectAid 那样容易整合
Both of these work as eclipse plug-ins, sorry that I don't know more about any command line tools that might be able to do what you're asking.
这两个都可以作为 Eclipse 插件使用,抱歉,我对任何可能能够执行您要求的命令行工具一无所知。
回答by vasanth
Try Google CodePro Analytix. the tool provides good insight about dependencies.
试试Google CodePro Analytix。该工具提供了有关依赖项的良好洞察力。
However I haven't tried using it from a command-line perspective. I expect it to support reports export, which can be parsed further down the tool-chain.
但是我还没有尝试从命令行的角度使用它。我希望它支持报告导出,可以在工具链中进一步解析。
回答by MikeThomas
You might UMLGraphuseful. It leverages GraphViz/dot as do most such graphing tools. I haven't used it, so I can't give a review of it, however.
你可能UMLGraph有用。它像大多数此类图形工具一样利用 GraphViz/dot。不过我没用过,所以没法评价。
That being said, you might also be able to roll your own minimalistic diagramming tool just using GraphViz and dot.
话虽如此,您也可以仅使用 GraphViz 和 dot 来推出自己的简约图表工具。
I've used GraphViz/dot to generate many useful types of diagrams, from visualizations of Spring contexts to IntelliJ module dependencies, to visualizations of complex XML documents. Look around and see what you find.
我使用 GraphViz/dot 生成了许多有用的图表类型,从 Spring 上下文的可视化到 IntelliJ 模块依赖关系,再到复杂 XML 文档的可视化。环顾四周,看看你发现了什么。
回答by lichengwu
Here is Class Dependency Analyzer (CDA) .
这是类依赖分析器(CDA)。
The purpose of this tool is to analyze Java? class files in order to learn more about the dependencies between those classes.
这个工具的目的是分析Java?class 文件,以便了解有关这些类之间的依赖关系的更多信息。
And here is the API:http://www.dependency-analyzer.org/#PluginAPI
回答by MartenCatcher
I'm use this functionality in my IDE - IntelliJ Idea
我在 IDE 中使用此功能 - IntelliJ Idea
See this page for more information and screenshots http://www.jetbrains.com/idea/features/uml_class_diagram.html
有关更多信息和屏幕截图,请参阅此页面http://www.jetbrains.com/idea/features/uml_class_diagram.html
回答by Gaket
If the question is still actual, try using the Code Iris plugin. It works with Intellij Idea http://plugins.jetbrains.com/plugin/7324
如果问题仍然存在,请尝试使用 Code Iris 插件。它适用于 Intellij Idea http://plugins.jetbrains.com/plugin/7324
It provides visual representation of dependency graph on classes, packages and modules level. Moreover, you can export data into json format.
它提供了类、包和模块级别的依赖图的可视化表示。此外,您可以将数据导出为 json 格式。
It is still updated and free.
它仍然是更新和免费的。
回答by Hilmar
From http://blog.schauderhaft.de/degraph/:
来自http://blog.schauderhaft.de/degraph/:
You can analyse class files and jars using Degraph and get a graphml file as result. This can be rendered using yed.
您可以使用 Degraph 分析类文件和 jar,并获得一个 graphml 文件作为结果。这可以使用 yed 呈现。
回答by Mark K Cowan
I just created a minimal tool which analyses and displays a graph of dependencies between packages, without much interaction or requiring other programs.
我刚刚创建了一个最小的工具,它分析和显示包之间的依赖关系图,不需要太多交互或需要其他程序。
https://github.com/battlesnake/jorgy
https://github.com/battlesnake/jorgy
It's quite undocumented as it's a quick hack project, but basically you run it and pass the path to your source directory as the first argument to it.
由于它是一个快速的 hack 项目,因此它完全没有记录,但基本上你运行它并将源目录的路径作为第一个参数传递给它。
It doesn't care about directory names or file names, but does require:
它不关心目录名或文件名,但确实需要:
package
declaration in each file.Exactly one type defined at the top-level (zero or many inner types nested within that are fine).
package
每个文件中的声明。仅在顶层定义了一种类型(嵌套在其中的零个或多个内部类型都可以)。
You can alter the GraphStyle
interface in the Application
class to suit your needs. This interface provides a way for you to tell the graph builder which dependencies are weak, which should not be shown on the graph, etc.
您可以更改类中的GraphStyle
界面Application
以满足您的需要。该接口为您提供了一种方法来告诉图形构建器哪些依赖项是弱的,哪些不应该显示在图形上等。
回答by Daniel Alencar
As for a command line tool, you may want to take a look at jdeps
:
至于命令行工具,你可能想看看jdeps
:
https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jdeps.html
https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jdeps.html
jdeps -cp <your cp> -v <path to your .class file>