java类图,如何过滤类路径的内容

af7jpaap  于 2021-07-07  发布在  Java
关注(0)|答案(1)|浏览(368)

我试图找到以下问题的答案。如果有人有什么提示,我会很感激的。
我尝试使用classgraph查找运行时类路径:

String classpath = new ClassGraph().getClasspath();

类路径内容如下所示:

C:\work\WildFlyAppServer\WildFlyAppServer14\jre\windows64\lib\ext\access-bridge-64.jar;
C:\work\WildFlyAppServer\WildFlyAppServer14\jre\windows64\lib\ext\cldrdata.jar;
C:\work\WildFlyAppServer\WildFlyAppServer14\jre\windows64\lib\ext\dnsns.jar;
C:\work\WildFlyAppServer\WildFlyAppServer14\jre\windows64\lib\ext\jaccess.jar;
C:\work\WildFlyAppServer\WildFlyAppServer14\jre\windows64\lib\ext\localedata.jar;
C:\work\WildFlyAppServer\WildFlyAppServer14\jre\windows64\lib\ext\nashorn.jar;
...

C:\work\dev\MyWebApplication\myapp\exploded-jb7\myapp.ear\myapp.war\WEB-INF\lib\myjar1.jar;
C:\work\dev\MyWebApplication\myapp\exploded-jb7\myapp.ear\myapp.war\WEB-INF\lib\myjar2.jar;
C:\work\dev\MyWebApplication\myapp\exploded-jb7\myapp.ear\myapp.war\WEB-INF\lib\myjar3.jar;
C:\work\dev\MyWebApplication\myapp\exploded-jb7\myapp.ear\myapp.war\WEB-INF\lib\myjar4.jar;
...

C:\work\WildFlyAppServer\WildFlyAppServer14\server\myapp\tmp\vfs\deployment\deployment82593206c83a71cc\myjar1.jar-a43b90541d67f63b\myjar1.jar;
C:\work\WildFlyAppServer\WildFlyAppServer14\server\myapp\tmp\vfs\deployment\deployment82593206c83a71cc\myjar2.jar-fc9118a07f840a67\myjar2.jar;
.....

C:\work\WildFlyAppServer\WildFlyAppServer14\modules\system\layers\base\com\sun\xml\bind\main\jaxb-core-2.3.0.jar;
C:\work\WildFlyAppServer\WildFlyAppServer14\modules\system\layers\base\com\sun\xml\bind\main\jaxb-runtime-2.3.0.jar;
....

例如,我想筛选来自以下位置的jar:c:\work\wildflyappserver\wildflyappserver14\server\myapp\tmp
有人知道怎么做吗?
谢谢!

llycmphe

llycmphe1#

尽管我没有使用classgraph,但是通过快速查看文档,我认为您应该使用此方法创建classgraph对象,并将此函数接口的实现作为参数传递。
基本上是这样的:

ClasspathElementFilter classpathElementFilter = (java.lang.String classpathElementPathStr) -> {
/* here check whether classpathElementPathStr is a path you want to scan. 
If yes return true */ 
}
ClassGraph myClassGraph = filterClasspathElements(classpathElementFilter);
String classpath = myClassGraph.getClasspath();

我希望这是有帮助的。

相关问题