[英]Maven Dependencies for Java Packages
I have a Java project with a standard Maven hierarchy:我有一个带有标准 Maven 层次结构的 Java 项目:
src
├── main
│ ├── java
│ │ └──com
│ │ └──foo
│ │ ├──bar
│ │ │ └──baz
│ │ └──qux
│ └── resources
└── test
How can I get a list of the dependencies used by the package com.foo.bar.baz
?如何获取包com.foo.bar.baz
使用的依赖项列表?
I was able to get this done using jdeps .我能够使用jdeps完成这项工作。 The usage is pretty simple:用法非常简单:
jdeps <options> <classes...>
Where <classes>
can be a pathname to a .class file, a directory, a JAR file, or a fully-qualified class name.其中<classes>
可以是 .class 文件、目录、JAR 文件或完全限定的类名的路径名。
Some of the options I found helpful in my case:我发现对我的案例有帮助的一些选项:
-verbose:class
: Print class-level dependencies excluding dependencies within the same package by default. -verbose:class
:默认打印类级依赖项,不包括同一包内的依赖项。-classpath <path>
:Specify where to find class files. -classpath <path>
:指定在哪里可以找到类文件。-package <pkgname>
: Finds dependences matching the given package name (may be given multiple times) -package <pkgname>
:查找与给定包名匹配的依赖项(可能多次给出)-regex <regex>
: Finds dependences matching the given pattern -regex <regex>
:查找与给定模式匹配的依赖项-filter <regex>
: Filter dependences matching the given pattern. -filter <regex>
:过滤器依赖匹配给定的模式。 If given multiple times, the last one will be used.如果多次给出,将使用最后一个。-filter:package
: Filter dependences within the same package (default) -filter:package
:过滤同一包内的依赖项(默认)-filter:archive
: Filter dependences within the same archive -filter:archive
:过滤同一存档中的依赖项-filter:none
: No -filter:package
and -filter:archive
filtering. -filter:none
:没有-filter:package
和-filter:archive
过滤。 Filtering specified via the -filter option still applies.通过 -filter 选项指定的过滤仍然适用。-include <regex>
: Restrict analysis to classes matching pattern. -include <regex>
:将分析限制为匹配模式的类。 This option filters the list of classes to be analyzed.此选项过滤要分析的类列表。-recursive
: Recursively traverse all dependencies. -recursive
:递归遍历所有依赖项。 Sample Usage for package com.abc.xyz.ui
:包com.abc.xyz.ui
示例用法:
jdeps.exe -filter:archive -classpath <project_classpath> com\abc\xyz\ui\
Where
<project_classpath>
is the classpath of the project.其中<project_classpath>
是项目的类路径。
Output:输出:
com.abc.xyz.ui (ui)
-> com.itextpdf.text itextpdf-5.5.12.jar
-> org.apache.commons.io commons-io-2.6.jar
-> org.apache.commons.lang3.time commons-lang3-3.8.1.jar
-> org.apache.commons.text commons-text-1.6.jar
-> org.controlsfx.control controlsfx-8.40.15.jar
-> java.io
-> java.lang
-> java.net
-> java.util
I used
-filter ^java\\..*
option to exclude Java Runtime classes:我使用-filter ^java\\..*
选项来排除 Java 运行时类:
jdeps.exe -filter:archive -filter ^java\..* -classpath <project_classpath> com\abc\xyz\ui\
Output:输出:
com.abc.xyz.ui (ui)
-> com.itextpdf.text itextpdf-5.5.12.jar
-> org.apache.commons.io commons-io-2.6.jar
-> org.apache.commons.lang3.time commons-lang3-3.8.1.jar
-> org.apache.commons.text commons-text-1.6.jar
-> org.controlsfx.control controlsfx-8.40.15.jar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.