Listing items on the Java classpath from the current project only

别来无恙 提交于 2019-12-01 11:56:44

问题


I have a Java project with a large classpath - many of the items are imported from different .jar files that have been added as dependencies (via Maven).

I'm looking for a programmatic way to list all the items on the classpath that come from the current project, i.e. excluding all the imported classpath items from other libraries and the Java runtime environment itself.

I need to do this at runtime, i.e. it should work off the actual current classpath.

Is there a good way to do this, and if so how?


回答1:


There is no way to do this unless you create your own metadata.

To the JVM, there is no distinction between items in the classpath. A jar is a jar is a jar.

You can use the maven-dependency-plugin to write out a list of the dependencies that are local, and not transitive, and write that into a file, and put that file in your application.



来源:https://stackoverflow.com/questions/13811981/listing-items-on-the-java-classpath-from-the-current-project-only

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!