查找冲突的jar文件

我们经常会遇到启动程序报错。jar包冲突的情况。
但是怎么知道冲突的类在哪些jar包里面呢。
一般报错都会有相类的冲突类。
把这个类拷贝放在下面的程序中:className
然后指定你项目的lib目录地址。
run !

package com.whaty.util;

import java.util.*;
import java.io.*;

public class JarClassFind {
	public static int count = 0;

	static public void main(String[] args) {
		/*
		 * if (args.length < 2) { showHowToUsage(); return; }
		 */
		String className = "DocumentBuilderFactoryImpl"; // 要查询的class,要带包名的类名
		String libPath = "E:/myeclipse65/bzz2/WebRoot/WEB-INF/lib"; // 所要查找的JAR包的目录

		String absoluteclassname = className.replace('.', '/') + ".class";

		System.out.println("Find class [" + className + "] in Path [" + libPath + "] Results:");
		FindClassInLocalSystem(libPath, absoluteclassname);
		if (JarClassFind.count == 0) {
			System.out.println("Error:Can't Find Such Jar File!");
		}
		System.out.println("Find Process Ended! Total Results:" + JarClassFind.count);
	}

	private static void FindClassInLocalSystem(String path, String classname) {
		if (path.charAt(path.length() - 1) != '\\') {
			path += '\\';
		}
		File file = new File(path);
		if (!file.exists()) {
			System.out.println("Error: Path not Existed! Please Check it out!");
			return;
		}
		String[] filelist = file.list();
		for (int i = 0; i < filelist.length; i++) {
			File temp = new File(path + filelist[i]);
			if ((temp.isDirectory() && !temp.isHidden() && temp.exists())) {
				FindClassInLocalSystem(path + filelist[i], classname);
			} else {
				if (filelist[i].endsWith("jar")) {
					try {
						java.util.jar.JarFile jarfile = new java.util.jar.JarFile(path + filelist[i]);
						for (Enumeration e = jarfile.entries(); e.hasMoreElements();) {
							String name = e.nextElement().toString();
							if (name.equals(classname) || name.indexOf(classname) > -1) {
								System.out.println("No." + ++JarClassFind.count);
								System.out.println("Jar Package:" + path + filelist[i]);
								System.out.println(name);
							}
						}
					} catch (Exception eee) {
					}
				}
			}
		}
	}

	public static void showHowToUsage() {
		System.out.println("Usage: Java -cp. JarClassFind <source path> <source class name>");
		System.out.println("Usage: Java -classpath. JarClassFind <source path> <source class name>");
		System.out.println("");
		System.out.println("<source path>:\t\tPath to Find eg:D:\\Jbuilder");
		System.out.println("<source class name>:\tClass to Find eg:java.applet.Applet");
	}
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值