`

Java程序调优---去掉 java 项目中 多余的jar包 方法

阅读更多

开发工具Eclipse 3.x


插件一:ClassPath Helper
插件地址:http://classpathhelper.sourceforge.net/

Downloading ClassPath Helper

For starters, you need to download the Classpath Helper eclipse plugins. The files are packaged seperately as binaries and source code plugins. The source code plugins are not required for execution.

The latest version of Classpath Helper can be downloaded from source forge http://classpathhelper.sourceforge.net/downloads.html

Once you download the eclipse distribution zip file, you need to unzip it in your eclipse directory (it will automatically unpack itself in the appropriate subdirectory (i.e. plugins). From there (re)start eclipse. You can verify if the classpath helper plugins are properly installed by selecting Help->About Eclipse SDK, select the "Plug-in Details" button.

Configuring Eclipse

Eclipse by default starts its VM with a very small heap and stack. This leads to some mysterous stack overflows from within Eclipse when plugins are performing long running jobs. This is a well documented bug within Eclipse that affects other plugins. The work around is to increase the stack size upon eclipse startup.

  eclipse.exe -Xms64m 

Opening Classpath Helper Views

The Classpath Helper Views can be opened in any perspective with the following steps.

First, from the Menu select Window->Show View->Other...

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

Second, under the Classpath Helper category, select the Classpath Helper ViewLocation By Location View, or Packages View

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

The Classpath Helper View

The basic layout of this view should be a straight forward translation of the classpath. The classpath is based upon the currently selected model (which initially is taken from the currently selected Java Project from you Package Explorer view).

Familar icons are used for Jar files and class folders. The order is represented top to bottom. The various decorations on these elements will be explained later.

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

This can be expanded to show the classes and interfaces within each jar or folder.

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

Unresolved Classes

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

The highlighted region shows a jar and class file decorated with a 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客. This indicates that a reference to a class cannot be resolved (found) on the current classpath. In this example, a class called anunresolvedjar.ClassMissingFromJar cannot be found. At runtime this would lead to either a java.lang.ClassNotFoundException or a java.lang.NoClassDefFoundError. In either case, the class anunresolvedjar.ClassWithMissingDependency cannot be loaded.

Blocked (Obscured) Classes

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

The first highlighted region (next to the 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客) shows jar and class file decorated with a 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客. This indicates a class is 'blocked' or 'obscured' on the classpath. This means that the class/interface located at this location will never be loaded. Instead it is loaded from another location. In this instance, we can see that the class ajar.DependsOnFilesFromFolder will actually be loaded from C:\Development\Sample\demoarea\ajar.jar.

In the second highlighted region (next to the 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客) we can see the class ajar.DependsOnFilesFromFolder. Although not a critical problem with the classpath, it could be confusing if the jar C:\Development\Sample\demoarea\ablockedjar.jar is updated with a new instance of ajar.DependsOnFilesFromFolder as the newer class will never get loaded into the JVM.

Blocked (Obscured) Classes with different versions

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

The first highlighted region (next to the 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客 shows a folder and class file with a 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客. This indicates a class is 'blocked' or 'obscured' on the classpath. This is essentially the same as a yellow rectangle with one addition. The red color is also an indication that the version of the class at this location (C:\Development\Sample\demoarea in this example) is different from the version that will actually be loaded (from C:\Development\Sample\build in this example). As with a yellow rectangle, the folder shown below the blocked class is the location where the class will actually get loaded from.

As with the previous example, the second highlight 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客 is showing the folder where the actual class will get loaded from. Of course blocking locations will always be above (appear earlier) in the classpath.

Unreferenced Classes

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

Classes decorated with the 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客 image indicates a class that is not referenced by any other class. In the above image afolder.AClassWithDependencies is not referenced by any other class. Keep in mind that this information is based solely on references maintained within the classfile itself. There are several notable cases where class files are referenced but this will not be indicated including:

  • In cases where Class.forName() is used to load a classes, which is common in many frameworks including struts, WAR web.xml files, EJB descriptors, etc.
  • Interface constants (static final constants) are compiled inline. This means that although there's a compile time dependency on the constants at runtime there is no reference to the declaring interface/class.

 

What a Class or Interface Depends On

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

In addition to showing issues or problems with the classpath, Classpath Helper also can be used to show what classes/interfaces a particular class depends on. The highlighted region shows that the class ajar.DependsOnFilesFromFolder depends on

  • afolder.AClassWithNoDependencies loaded from C:\Development\Sample\demoarea
  • blocked.BlocksALaterClass loaded from C:\Development\Sample\build

 

Referenced By

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

In addition to showing locations and classes a class depends on, it is also possible to see which classes refer to a given class. In the above image you can see the class SomeInterface is referenced by blocked.BlocksALaterClass (which is located in the C:\Development\Sample\build folder).

Filtering

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客
去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客  去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客
去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客  去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客
去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客  去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

It is possible to apply filtering to the Classpath Helper view. Filtering will only show jars/folders/classes/packages that relate to selected filtering criteria.

The Location by Location View

The layout of this view initially appears identical to the ClasspathHelper view, however it is intended to show relationships between jars. The decorative icons are the same and essentially have the same meaning. But the Location by Location view can be used to view inter jar information.

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

This can be expanded in a similar fashion.

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

Depends On

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

The Depends on branch shows which jars/folders that this particular jar depends on. In this case ajar.jar depends on both the build and demoarea folders. Within each folder we can see the specific classes that are depended on.

Also notice the unreferenced icon 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客. As with the classpath helper view, this indicates that the object is unreferenced. However in this view the icon indicates a jar that is not referenced at runtime by any other jar. This can be useful in locating obsolete jars.

Referenced By

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

The Referenced by Branch is the reverse of the depends on view. It shows which jars a particular jar supports or is referred to by. In this case, demoarea is referenced by itself and ajar.jar. The references are afolder.AClassWithDependencies and ajar.DependsOnFilesFromFolders. The specific class referenced isafolder.AClassWithNoDependencies which is refered to by both.

Unresolved

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

The unresolved branch is similar to unresolved branch from the ClassPath view. The only difference is that it is showing a summary of unresolved classes for the entire jar. In this case anunresolvedjar.ClassMissingFromJar cannot be found.

The Package View

This view takes a package centric view of the classpath, allowing you to look for classes without knowing or caring about the location of the class. The decorative icons are the same and have the same meaning as the other views.

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

Packages can be expanded to reveal the contents of a package.

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

Unresolved Classes

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

The highlighted region shows a package and class file decorated with a 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客. This indicates that a reference to a class cannot be resolved (found) on the current classpath. In this example, a class called anunresolvedjar.ClassMissingFromJar cannot be found. At runtime this would lead to either a java.lang.ClassNotFoundException or a java.lang.NoClassDefFoundError. In either case, the class anunresolvedjar.ClassWithMissingDependency cannot be loaded.

Blocked (Obscured) Classes

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

The first highlighted region (next to the 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客) shows the class file DependsOnFilesFromFolder decorated with a 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客. This indicates the class is 'blocked' or 'obscured' on the classpath. This means that the class/interface is available at multiple locations on the classpath. The list shows areas where this class is blocked.

The second highlighted region (next to the 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客) shows where the class would actually be loaded from.

Blocked (Obscured) Classes with different versions

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

The first highlighted region (next to the 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客 shows the class BlocksALaterClass file with a 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客. This indicates it is is 'blocked' or 'obscured' on the classpath. This is essentially the same as a yellow rectangle with one addition. The red color is also an indication that the version of the class at this location (C:\Development\Sample\demoarea in this example) is different from the version that will actually be loaded (from C:\Development\Sample\build in this example). As with a yellow rectangle, the folder shown below the blocked class is the location where the class will actually get loaded from.

As with the previous example, the second highlight 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客 is showing the folder where the actual class will get loaded from. Of course blocking locations will always be above (appear earlier) in the classpath.

What a Class or Interface Depends On

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

In addition to showing issues or problems with the classpath, Classpath Helper also can be used to show what classes/interfaces a particular class depends on. The highlighted region shows that the class ajar.DependsOnFilesFromFolder depends on

  • afolder.AClassWithNoDependencies loaded from C:\Development\Sample\demoarea
  • blocked.BlocksALaterClass loaded from C:\Development\Sample\build

 

Referenced By

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

In addition to showing locations and classes a class depends on, it is also possible to see which classes refer to a given class. In the above image you can see the class SomeInterface is referenced by blocked.BlocksALaterClass (which is located in the C:\Development\Sample\build folder).

Filtering

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客 去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客
去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客  去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客
去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客  去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客
去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客  去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

It is possible to apply filtering to the Classpath Helper view. Filtering will only show jars/folders/classes/packages that relate to selected filtering criteria.

Not on Classpath View

This view scans for jars that are not on the classpath (but are under the current project). It provides basic browsing of packages and classes that are available but not on the classpath. This can be helpful when trying to build up a classpath, as you can quickly browse for the missing classes to see which jars contain them.

Available locations

去掉 java 项目中 多余的jar包 方法 - abcijkxyz - 余威的博客

The only information this view shows is which jars a class or interface can be loaded from. Only jars from the current Eclipse project that are not already on the classpath are scanned (this image was created by removing previously demoed jars from the classpath).

插件二:Classpath Checker
插件地址:http://classpathchecker.free.fr/


Classpath Checker @ Eclipse Plugin Central

 

Classpath Checker Eclipse Plugin v1.4.3

Description

  1. The Classpath Checker eclipse plugin detects classpath inconsistencies in Java projects.

    That means it is able to:
  2. Detect if a jar file is missing in your classpath. In case a class in your classpath depends on other classes that are not present in the classpath, the plugin warns you and gives you the missing class names.
  3. Detect if you have some duplicated classes in all your jar files. In case of duplicated classes, this plugin warns you. If there are version conflicts in the duplicated classes, it helps you to determine which is the wrong Jar to remove from your classpath.

Why do I need this plugin?

As you know, current java projects depend of more and more external libraries, and 3rd party products. Obviously, each 3rd party product embeds its own libraries, consequently it becomes very difficult to be sure there are no classpath problems in the application. One terrible behavior is when the libraries order becomes important in the classpath! That's why Classpath Checker can help you.

Installation

  1. This plugin has been tested on Eclipse 3.3.0 (Europa) only.

    To install the Classpath Checker plugin:
    Click here if you have the version (v1.1.0)
  2. In Eclipse, click on Help -> Software Update -> Find and Install...
  3. Choose the Search for new features to install option, and click Next.
  4. Click New Remote Site.
  5. Enter the following: and click OK.
  6. "Classpath Checker" should appear under Sites to include in search
    Click the checkbox next to it to select it, and click Finish.
  7. You should see Classpath Checker under Select features to install
    (You may have to click on one or two triangles to make it visible in the tree.) 
    Select the checkbox next to it and click next.
  8. Select the I accept option to accept the license and click Next.
  9. Make sure the location is correct where you're installing it. The default (your workspace) should be fine. Click Finish.
  10. The plugin is not digitally signed. Go ahead and install it anyway.
  11. Click Yes to make Eclipse restart itself.

How to use it?

After installing the plugin, you have to right click on your java project, then select "Properties".
The following dialog is displayed, select the "Classpath Checker" section, and then check the "Activate classpath checker".

2
1
分享到:
评论
1 楼 大大灰狼 2014-10-22  
第一个不知道是不是我的Eclipse版本太高了,没法使用;
第二个不是清理jar包的吧...

相关推荐

    Java程序调优插件ClassPath Helper/classpathchecker

    Java程序调优---去掉 java 项目中 多余的jar包 两个插件 一、ClassPath Helper 说明: 1.depends on:表示该类依赖于下面的jar包列表。 2.refrenced by:表示该类被下面的jar列表所依赖。 3.unresolved references:...

    java server-jre-8u60-windows-x64.gz

    Java Server-JRE 8u60 是Oracle公司提供的一个针对服务器环境优化的Java运行时环境(JRE),专为在Windows 64位系统上执行Java应用程序而设计。这个版本的JRE包含了运行和部署Java应用程序所需的核心组件,但不包含...

    java版本DBSCAN

    - 用户在导入Java版DBSCAN时,需要将对应的库文件(jar或源码)添加到项目的类路径中。 - 调用DBSCAN类的实例化方法,设置`eps`和`minPts`参数,然后传入数据集进行聚类操作。 - 获取聚类结果,通常表现为一个...

    JAVA相关资料

    Java的语法与C++相似,但更注重代码的简洁性和可读性,同时也去除了C++中的一些容易引发错误的特性,如指针操作。 1. **基础概念** - **类与对象**:Java的核心是面向对象编程,其中类是对象的蓝图,而对象是类的...

    java使用卷积神经网络的用法

    在Java中实现CNN进行自然语言情感化分析,通常会涉及以下关键步骤: 1. **数据预处理**:首先,你需要将文本数据转化为机器可理解的形式。这可能包括分词、去除停用词、词干提取等。对于情感分析,你还需要将每个...

    java 验证码识别源程序

    总之,Java验证码识别源程序是一个结合了图像处理和机器学习技术的项目,它可以帮助我们自动化处理那些需要人工输入验证码的场景,提高了效率并降低了错误率。不过,为了确保其在各种复杂验证码上的有效性,持续的...

    关键字所用的jar包

    在这个场景中,"关键字所用的jar包"指的是在实现搜索功能时所依赖的一系列Java档案(JAR)文件。这些JAR包包含了必要的类和方法,允许程序员构建高效的全文检索系统。以下是标题和描述中提到的关键知识点以及它们的...

    Java程序性能优化 让你的Java程序更快、更稳定

    Java程序性能优化是每个开发人员都需要关注的重要领域,它涵盖了多个方面,旨在提高代码执行效率,减少资源消耗,提升系统稳定性。以下是一些关键的Java性能优化知识点: 1. **JVM调优**:理解JVM的工作原理是优化...

    eclipse调优及使用

    5. **解决Ctrl键卡死问题**:在`Hyperlinking`设置中去掉`Enable on demand hyperlink style navigation`选项,或者针对特定文件类型禁用该功能,以避免在大文件中按Ctrl键时的延迟。 ### 其他设置 1. **代码折叠...

    MyEc;ipse调优

    在开发Java应用程序时,MyEclipse作为一款强大的集成开发环境,其性能优化显得尤为重要。对于开发效率和系统资源的高效利用,MyEclipse的调优是必不可少的一环。本文将详细介绍MyEclipse的调优方法,包括界面配置、...

    hibernate 4.2.4精简jar包

    在这个“hibernate 4.2.4精简jar包”中,包含了 Hibernate 框架的核心组件,使得开发者能够在项目中快速集成和使用Hibernate 4.2.4版本。 1. **Hibernate ORM框架**: Hibernate 是一个开放源代码的 ORM 解决方案,...

    Java程序性能优化之二十三个建议

    9. **本地方法缓存**:如果Java程序需要调用本地方法,使用`sun.misc.Unsafe`或JNI可以实现本地方法缓存,减少方法调用的开销。 10. **使用最新版本的JDK**:每个新版本的JDK都会包含性能改进,更新到最新版本可以...

    人工智能-项目实践-搜索引擎-基于java开发的分布式搜索引擎

    本项目聚焦于【人工智能】在实际应用中的一个关键场景——【分布式搜索引擎】的开发,主要使用了编程语言【Java】进行实现。 分布式搜索引擎的核心优势在于其可扩展性和高可用性,它可以将搜索任务分散到多台服务器...

    阿里巴巴JAVA开发规范word和pdf去水印高清版

    《阿里巴巴JAVA开发规范》是Java开发者们不可或缺的参考资料,它为Java编程设定了明确的指导准则,旨在提高代码质量,提升开发效率,确保项目的稳定性和可维护性。这份规范不仅适用于阿里巴巴集团内部,也被广大开源...

    JAVA 开发搜索链接淘特搜索引擎共享版-tot-search-engine

    在"JAVA 开发[搜索链接]淘特搜索引擎共享版_tot_search_engine"项目中,开发者可能已经将上述一些或所有功能整合到了一个可部署的解决方案中。由于这是一个共享版,它可能包含了基本的搜索功能,允许其他开发者在其...

    MyEclipse之调优

    MyEclipse是一款强大的Java集成开发环境,以其丰富的功能和便捷的开发体验深受程序员喜爱。然而,随着插件的增多,MyEclipse的启动速度和运行效率可能会受到影响,导致开发过程中的等待时间增加。本文将针对...

    Java语言入门级的十二大特色详细介绍

    Java语言在设计上尽可能地简化了C++中复杂的特性,如去除了运算符重载、预处理指令、指针操作、结构体、联合体、多维数组、模板和隐式类型转换等。这种简化不仅降低了学习难度,也让Java更加专注于核心功能,使得...

    java文本分类.zip

    6. **模型调优与部署**:通过网格搜索、随机搜索等方法找到最佳模型参数,并将训练好的模型部署到实际应用中,用于自动化文本分类。 在Java中,实现这些步骤可以使用诸如Apache OpenNLP、Stanford NLP、GATE...

    java资料.rar

    Java通过异常类来处理程序中的错误或异常情况,提供了try-catch-finally语句块进行异常捕获和处理。 6. **垃圾回收与内存管理** JVM自动管理内存,通过垃圾回收机制回收不再使用的对象,避免内存泄漏。 7. **...

    基于gpt3.5对话 实现Java情感分析的对话过程

    然后,我们需要编写代码将数据加载到Java程序中。 接下来,我们需要对数据进行预处理,例如清洗、分词、去除停用词、标准化等操作。对于文本情感分析,可以使用词袋模型(Bag-of-Words)将文本转换为向量表示。对于...

Global site tag (gtag.js) - Google Analytics