java项目删除多余jar包_[转载]去掉 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

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

a4c26d1e5885305701be709a3d33442f.png

Second, under the Classpath

Helper category, select

the Classpath

Helper View, Location By Location View,

or Packages

View

a4c26d1e5885305701be709a3d33442f.png

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.

a4c26d1e5885305701be709a3d33442f.png

This can be expanded to show the classes and

interfaces within each jar or folder.

a4c26d1e5885305701be709a3d33442f.png

Unresolved Classes

a4c26d1e5885305701be709a3d33442f.png

The highlighted region shows a jar and class file

decorated with a a4c26d1e5885305701be709a3d33442f.png.

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

a4c26d1e5885305701be709a3d33442f.png

The first highlighted region (next to

the a4c26d1e5885305701be709a3d33442f.png)

shows jar and class file decorated with

a4c26d1e5885305701be709a3d33442f.png.

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:DevelopmentSampledemoareaajar.jar.

In the second highlighted region (next to

the a4c26d1e5885305701be709a3d33442f.png)

we can see the class ajar.DependsOnFilesFromFolder. Although

not a critical problem with the classpath, it could be confusing if

the jar C:DevelopmentSampledemoareaablockedjar.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

a4c26d1e5885305701be709a3d33442f.png

The first highlighted region (next to

the a4c26d1e5885305701be709a3d33442f.png shows

a folder and class file with a a4c26d1e5885305701be709a3d33442f.png.

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:DevelopmentSampledemoarea in

this example) is different from the version that will actually be

loaded (from C:DevelopmentSamplebuild 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 a4c26d1e5885305701be709a3d33442f.png 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

a4c26d1e5885305701be709a3d33442f.png

Classes decorated with

the a4c26d1e5885305701be709a3d33442f.png 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

a4c26d1e5885305701be709a3d33442f.png

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:DevelopmentSampledemoarea

blocked.BlocksALaterClass loaded

from C:DevelopmentSamplebuild

Referenced By

a4c26d1e5885305701be709a3d33442f.png

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:DevelopmentSamplebuild folder).

Filtering

a4c26d1e5885305701be709a3d33442f.pnga4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

 a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

 a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

 a4c26d1e5885305701be709a3d33442f.png

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.

a4c26d1e5885305701be709a3d33442f.png

This can be expanded in a similar fashion.

a4c26d1e5885305701be709a3d33442f.png

Depends On

a4c26d1e5885305701be709a3d33442f.png

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 a4c26d1e5885305701be709a3d33442f.png.

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

a4c26d1e5885305701be709a3d33442f.png

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

a4c26d1e5885305701be709a3d33442f.png

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.

a4c26d1e5885305701be709a3d33442f.png

Packages can be expanded to reveal the contents of a

package.

a4c26d1e5885305701be709a3d33442f.png

Unresolved Classes

a4c26d1e5885305701be709a3d33442f.png

The highlighted region shows a package and class file

decorated with a a4c26d1e5885305701be709a3d33442f.png.

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

a4c26d1e5885305701be709a3d33442f.png

The first highlighted region (next to

the a4c26d1e5885305701be709a3d33442f.png)

shows the class file DependsOnFilesFromFolder decorated

with a a4c26d1e5885305701be709a3d33442f.png.

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

shows where the class would actually be loaded from.

Blocked (Obscured) Classes with different

versions

a4c26d1e5885305701be709a3d33442f.png

The first highlighted region (next to

the a4c26d1e5885305701be709a3d33442f.png shows

the class BlocksALaterClass file

with a a4c26d1e5885305701be709a3d33442f.png.

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:DevelopmentSampledemoarea in

this example) is different from the version that will actually be

loaded (from C:DevelopmentSamplebuild 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 a4c26d1e5885305701be709a3d33442f.png 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

a4c26d1e5885305701be709a3d33442f.png

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:DevelopmentSampledemoarea

blocked.BlocksALaterClass loaded

from C:DevelopmentSamplebuild

Referenced By

a4c26d1e5885305701be709a3d33442f.png

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:DevelopmentSamplebuild folder).

Filtering

a4c26d1e5885305701be709a3d33442f.pnga4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

 a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

 a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

 a4c26d1e5885305701be709a3d33442f.png

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

a4c26d1e5885305701be709a3d33442f.png

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 v1.4.3

Description

The Classpath Checker eclipse

plugin detects

classpath inconsistencies in Java

projects.

That means it is able to:

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.

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.

In Eclipse, click

on Help-> Software

Update-> Find and

Install...

Choose the Search for new features to

installoption, and

click Next.

Click New Remote Site.

Enter the following:

OK.

"Classpath Checker" should appear

under Sites to

include in search. Click the checkbox next to it to select it, and

click Finish.

You should

see Classpath

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

Select the I acceptoption to accept

the license and click Next.

Make sure the location is correct

where you're installing it. The default (your workspace) should be

fine. Click Finish.

The plugin is not digitally signed.

Go ahead and install it anyway.

Click Yesto 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".

a4c26d1e5885305701be709a3d33442f.png

Then after a full build, you can provoke it, by clicking on

"Project/clean..." in the eclipse menu, you get errors or warnings

on your project.

a4c26d1e5885305701be709a3d33442f.png

For each problem you can right click and select "Show Conflict

Details". This action opens the view "Classpath Checker Details"

that display more information on the problem.

a4c26d1e5885305701be709a3d33442f.png

In order to help you to find what is the problem, you can click on

an impacted jar that will open its associated Manifest file. That

is usefull to check the jar versions. To have a better

understanding of what is the problem, you can click on a class that

will open the description view of the selected class.

Version History

1.4.3

Support of Eclipse

Ganymede (The "Show Conflict Details" popup menu was not

availaible)

1.4.2

Bugs fix

1.4.1

Bugs fix

1.4.0

New Feature: "Libraries

to exclude" groups the libraries by category

New Feature: The build is now optimized and runs only when there is

a change in the classpath

New property: To search only for duplicate classes

New property: To search only for missing classes

Bugs fix

1.3.0

Property change: "class

exclusion pattern" replaced by "libraries to exclude"

Bugs fix

1.2.0

New Feature: Detect

missing classes in the classpath

New Property: To limit the number of error or warning

New Property: To ignore warnings Bugs fix

Installation

steps if you have the version 1.1.0:

To upgrade you must first uninstall

the previous version.

In eclipse: Help/Software

Updates/Manage Configuration

Right-Click on "Classpath Checker

Feature 1.1.0" and select Uninstall.

After the uninstall, re-start

eclipse.

1.1.0

Improve performance

Bugs fix

1.0.0

Initial Version

Detect multiple class versions in the classpath

Additional Information

Please send an email to classpathchecker@free.fr for

your comments, suggestions and/or bug.

Visit the author's web site:

插件三:UCDetector:

Unnecessary Code Detector

插件地址:http://www.ucdetector.org/

a4c26d1e5885305701be709a3d33442f.png UCDetector:

Unnecessary Code Detector

Start

About

UCDetector (Unnecessary Code Detector - pronounced "You See

Detector") is a eclipse PlugIn tool to find unnecessary

(dead) public java

code. For example public classes, methods or fields which have no

references. UCDetector creates markers for the following problems,

which appear in the eclipse problem view:

Unnecessary (dead) code

Code where the visibility could be

changed to protected, default

orprivate

Methods of fields, which can

be final

a4c26d1e5885305701be709a3d33442f.png If you can't see the pop menu above, read

Get UCDetector

UCDetector needs Eclipse >= 3.5 and java

>= 5.0. (For older versions:Eclipse

3.2, RAD, Eclipse

3.3, 3.4 ) Download:

Download org.ucdetector_x.y.z.jar

Put org.ucdetector_x.y.z.jar

into ECLIPSE_HOME/dropins directory

Restart Eclipse

Eclipse update

site: http://ucdetector.sourceforge.net/update

Quick start

Instead of clicking Shift+Ctrl+G (search references in workspace)

all the time, follow the next steps:

In the package explorer right click

on a project, package or class

Select the context menu:

UCDetector/detect unnecessary code a4c26d1e5885305701be709a3d33442f.png

Check warnings in java editor and

Problems View a4c26d1e5885305701be709a3d33442f.png a4c26d1e5885305701be709a3d33442f.png a4c26d1e5885305701be709a3d33442f.png a4c26d1e5885305701be709a3d33442f.png a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png a4c26d1e5885305701be709a3d33442f.png

Use the menu "Group By/Type" in

Problems View

Change code carefully. Use QuickFixes

(right click on markers)

Change preference "Detect code with

max number of references" from 0 to 1, run UCDetector again

Repeat step 1. to 5.

Really want to change code?

The problems found by UCDetector, are only

suggestions. Before changing code, you should really know what you

are doing!If UCDetector tells you, that

there are no references your code still may be used by:

Reflection

Frameworks like Spring, Hibernate or

Eclipse which declare dependencies in property files, xml files

(extension-points) ...

Third party code, which is using your

API

Jars in your workspace

To be continued...

Change visibility may cause problems with inheritance, reflection,

instantiation...

It's good idea to do a full text search in workspace for the piece

of code, you want to change.

a4c26d1e5885305701be709a3d33442f.png

Change code, use QuickFixes!

After checking carefully all the possibilities above, maybe you

decide to change your code. Click on the marker to see QuickFixes's

to change code:

Delete code: When UCDetector tells

you that there are no references

Move code: When UCDetector tells you

that there is only 1 reference (change UCDetector preference

"Detect code with max number of references" to 1

Change visibility:

Use protected ,

default or private

Use final

It is possible to change several problems at once using quick fix

dialog.

a4c26d1e5885305701be709a3d33442f.png

Ignore code

// NO_UCD

public class BeanExample { // NO_UCD

@SuppressWarnings("ucd")

@SuppressWarnings("ucd") public class BeanExample {

@UsedBy("reflection")

I don't like this one, but users asked for it:

If you want to "polute" your code, you can use the@org.ucdetector.util.UsedBy annotation

located inside ucdetector-annotations.jar which is inside

org.ucdetector.source_x.y.z.zip.

@UsedBy("reflection") public class BeanExample {

a4c26d1e5885305701be709a3d33442f.png

Set eclipse compiler setting "Unhandled token in

'@SuppressWarnings'" to Ignore

To avoid eclipse Warnings "Unsupported

@SuppressWarnings("ucd")"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值