简体   繁体   English

如何针对Java中的类检查库的依赖关系

[英]How to check dependencies of libraries against classes in java

I have a java project which is previously developed by another developer, in this application there are a lot of unnecessary libraries. 我有一个Java项目,该项目先前是由另一个开发人员开发的,在此应用程序中有很多不必要的库。 I was able to delete some of those libraries. 我能够删除其中一些库。 But, as there are a lot of them I want to know whether there is a technique to scan the project and detect unrelated libraries to the project. 但是,由于它们很多,我想知道是否存在一种扫描项目并检测与项目无关的库的技术。

我推荐JBoss的Tattletale

Depending on the build method, it should be easy to remove unnecessary libraries without deleting/adding them by simply recompiling the application modifying the classpath at compile time, or rather modifying the build files by one-by-one deletion of lib dependencies. 根据构建方法的不同,只需在编译时重新编译修改类路径的应用程序,或者通过逐一删除lib依赖项来修改构建文件,就可以轻松地删除不必要的库,而无需删除/添加它们。 Either one of these methods will require no manual deletion of jars. 这些方法之一都不需要手动删除jar。

1) If you set the jars using the classpath manually, you can play with classpath wild cards to remove / add different jars when running : Setting multiple jars in java classpath classpaths . 1)如果您手动使用classpath设置jar,则可以在运行时使用classpath通配符来删除/添加不同的jar: 在java classpath classpaths中设置多个jar This does not require manual deletion / adding of jars. 这不需要手动删除/添加罐子。

2) Find the dependencies definition (pom.xml in maven, ivy.xml for some ant projects). 2)找到依赖项定义(在maven中为pom.xml,对于某些ant项目为ivy.xml)。

and One by one delete the (maven) 然后一一删除(maven)

<dependency>..</dependency> 

or (ivy) 或(ivy)

<dependency .... />

entries in your build file. 构建文件中的条目。

If you have the correct build plugins installed - then your IDE will immediately rebuild the project using your new definitions (no error prone removal/deletion of jars or classpath entries). 如果您安装了正确的构建插件-那么您的IDE将立即使用您的新定义重新构建项目(不容易删除或删除jar或类路径条目)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM