仅列出当前项目中Java类路径上的项目 [英] Listing items on the Java classpath from the current project only

查看:95
本文介绍了仅列出当前项目中Java类路径上的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有大类路径的Java项目-许多项目是从不同的.jar文件导入的,这些文件已作为依赖项添加(通过Maven)。

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).

我正在寻找一种编程方式,以列出来自当前项目的类路径上的所有项,即排除从其他库和Java运行时环境本身导入的所有类路径项。

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.

有什么好方法吗?

推荐答案

除非您创建自己的元数据,否则无法这样做。

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

对于JVM,类路径中的项目之间没有区别。一个罐子就是一个罐子。

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

您可以使用 maven-dependency-plugin 来写出本地的而不是可传递的依赖项列表,并将其写入文件,然后将该文件放入您的应用程序。

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.

这篇关于仅列出当前项目中Java类路径上的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆