Java 查找 Eclipse 项目中使用的未使用的 jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/248589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Finding unused jars used in an eclipse project
提问by RodeoClown
Are there any plugins/tools available to go through the classpath of an eclipse project (or workspace) and highlight any unused jars?
是否有任何插件/工具可用于通过 eclipse 项目(或工作区)的类路径并突出显示任何未使用的 jars?
采纳答案by VonC
ClassPathHelperis a good start.
ClassPathHelper是一个好的开始。
It automatically identifies orphan jars and much more.
它会自动识别孤儿罐子等等。
The only limitation is with dependencies that are not defined in classes, e.g. in dependency injection framework configuration files.
唯一的限制是没有在类中定义的依赖项,例如在依赖项注入框架配置文件中。
You also have other options/complements, such as:
您还有其他选项/补充,例如:
- workingfrog "Relief", which relies on the ability to deal with real objects by examining their shape, size or relative place in space it gives a "physical" view on java packages, types and fields and their relationships, making them easier to handle.
- Unnecessary Code Detector: a eclipse PlugIn tool to find unnecessary (dead) public java code.
- workingfrog "Relief"依赖于通过检查真实对象的形状、大小或在空间中的相对位置来处理真实对象的能力,它提供了 Java 包、类型和字段及其关系的“物理”视图,使它们更容易处理。
- 不必要的代码检测器:一个 Eclipse 插件工具,用于查找不必要的(死的)公共 Java 代码。
回答by VonC
You can use one of this plugins: UCDetectoror Classpath Helper
您可以使用以下插件之一: UCDetector或Classpath Helper
回答by Raphael Jolivet
UCDetectordoes not help for this : It does not work on JARs. And for classpathHelper, I wan't able to find out an easy way just to list the orphan JARs (BTW, if someone has a tutorial for this, i am interested).
UCDetector 对此没有帮助:它不适用于 JAR。对于classpathHelper,我无法找到一种简单的方法来列出孤立的 JAR(顺便说一句,如果有人有这方面的教程,我很感兴趣)。
So, if you are also using Maven as I do, I find out this great Maven plugin, and I would like to share this solution with you. Just type :
所以,如果你也像我一样使用 Maven,我会发现这个很棒的 Maven 插件,我想与你分享这个解决方案。只需输入:
mvn dependency:analyze
And you will instantly get a list of unused JARs in your dependencies. Very handy !
您将立即获得依赖项中未使用的 JAR 列表。非常便利 !
回答by Jon Carlstedt
I know this is an old one, but if anyone else stumbles upon this, Eclipse does this by itself.
我知道这是一个旧的,但如果其他人偶然发现了这一点,Eclipse 会自行完成。
Navigate to Project properties->Java Code Style->Clean Up Select the Eclipse [Built-in] and it does the following:
导航到 Project properties->Java Code Style->Clean Up 选择 Eclipse [Built-in] 并执行以下操作:
- Change non static accesses to static members using declaring type
- Change indirect accesses to static members to direct accesses (accesses through subtypes)
- Remove unused imports
- Add missing '@Override' annotations
- Add missing '@Override' annotations to implementations of interface methods
- Add missing '@Deprecated' annotations
- Remove unnecessary casts
- Remove unnecessary '$NON-NLS$' tags
- 使用声明类型更改对静态成员的非静态访问
- 将对静态成员的间接访问更改为直接访问(通过子类型访问)
- 删除未使用的导入
- 添加缺少的“@Override”注释
- 将缺少的“@Override”注释添加到接口方法的实现中
- 添加缺少的“@Deprecated”注释
- 删除不必要的演员表
- 删除不必要的“$NON-NLS$”标签
回答by bobbel
I found a very fast and interesting tool to archive this goal:
我找到了一个非常快速和有趣的工具来归档这个目标:
Just unzip the program and run:
只需解压缩程序并运行:
java -Xmx512m -jar tattletale.jar ~/myjavaproject/mydistribution output
This will generate a very impressive report with different points (text from their site):
这将生成一个非常令人印象深刻的报告,其中包含不同的点(来自他们网站的文本):
- Identify dependencies between JAR files
- Find missing classes from the classpath
- Spot if a class/package is located in multiple JAR files
- Spot if the same JAR file is located in multiple locations
- With a list of what each JAR file requires and provides
- Verify the SerialVersionUID of a class
- Find similar JAR files that have different version numbers
- Find JAR files without a version number
- Find unused JAR archives
- Identify sealed / signed JAR archives
- Locate a class in a JAR file
- Get the OSGi status of your project
- Remove black listed API usage
- And generate the same reports for your .WAR and .EAR archives
- 识别 JAR 文件之间的依赖关系
- 从类路径中查找缺失的类
- 发现一个类/包是否位于多个 JAR 文件中
- 发现同一个 JAR 文件是否位于多个位置
- 列出每个 JAR 文件需要和提供的内容
- 验证类的 SerialVersionUID
- 查找具有不同版本号的类似 JAR 文件
- 查找没有版本号的 JAR 文件
- 查找未使用的 JAR 档案
- 识别密封/签名的 JAR 档案
- 在 JAR 文件中定位一个类
- 获取项目的 OSGi 状态
- 移除黑名单 API 使用
- 并为您的 .WAR 和 .EAR 档案生成相同的报告