jar包冲突解决方法
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class ClearConflict
{
List<ClassJarPair> classList = new ArrayList<ClassJarPair>();
List<String> jarList = new ArrayList<String>();
/**
* 生成输出格式
*
* @param name 输出的文件名或目录名
* @param level 输出的文件名或者目录名所在的层次
* @return 输出的字符串
*/
public String createPrintStr(String name, int level)
{
// 输出的前缀
String printStr = "";
// 按层次进行缩进
for (int i = 0; i < level; i++)
{
printStr = printStr + " ";
}
printStr = printStr + "- " + name;
return printStr;
}
/**
* 输出初始给定的目录
*
* @param dirPath 给定的目录
*/
public void printDir(String dirPath)
{
// 将给定的目录进行分割
String[] dirNameList = dirPath.split("\\\\");
// 按格式输出
for (int i = 0; i < dirNameList.length; i++)
{
System.out.println(createPrintStr(dirNameList[i], i));
}
}
/**
* 输出给定目录下的文件,包括子目录中的文件
*
* @param dirPath 给定的目录
*/
public void readFile(String dirPath)
{
// 建立当前目录中文件的File对象
File file = new File(dirPath);
// 取得代表目录中所有文件的File对象数组
File[] list = file.listFiles();
// 遍历file数组
for (int i = 0; i < list.length; i++)
{
if (list[i].isDirectory())
{
// 递归子目录
readFile(list[i].getPath());
}
else
{
if (list[i].isFile())
{
try
{
if ((list[i].getCanonicalFile() + "").endsWith(".jar"))
{
// System.out.println(list[i].getCanonicalFile()+"");
JarFile jar = new JarFile(list[i].getCanonicalFile() + "");
Enumeration<JarEntry> entrys = jar.entries();
while (entrys.hasMoreElements())
{
JarEntry jarEntry = entrys.nextElement();
if (jarEntry.getName().endsWith("class"))
{
int index =
classList.indexOf(new ClassJarPair(list[i].getCanonicalFile() + "",
jarEntry.getName() + ""));
if (0 < index)
{
String jar1 = list[i].getCanonicalFile() + "";
String jar2 = classList.get(index).getJarName();
if (jarList.contains(list[i].getCanonicalFile() + ""))
{
;
}
else
{
System.out.printf("%20s CONFILT WITH JAR: %20s",
jar2.substring(jar2.lastIndexOf("\\") + 1),
jar1.substring(jar1.lastIndexOf("\\") + 1));
jarList.add(list[i].getCanonicalFile() + "");
System.out.print();
}
/*
* System.out.print("the jar: "+list[i].getCanonicalFile()+" confilt with Jar: "
* + classList.get(index).getJarName());
* System.out.println("has the same class: "+jarEntry.getName());
*/
}
else
{
classList.add(new ClassJarPair(list[i].getCanonicalFile() + "",
jarEntry.getName() + ""));
}
}
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
}
/**
* @param args
* @throws IOException
*/
public static void main(String[] args)
throws IOException
{
File dir = null;
if (0 == args.length)
{
dir = new File("");
}
else if (1 == args.length)
{
dir = new File(args[0]);
}
else
{
System.out.println("Usage: java ClearConflict libpath");
}
System.out.println(dir.getAbsoluteFile());
ClearConflict cl = new ClearConflict();
String dirPath = dir.getAbsoluteFile() + "";
cl.readFile(dirPath);
}
class ClassJarPair
{
private String jarName;
private String className;
ClassJarPair(String jarName, String className)
{
this.jarName = jarName;
this.className = className;
}
@Override
public boolean equals(Object obj)
{
ClassJarPair classJarPair = (ClassJarPair)obj;
return className.equals(classJarPair.getClassName());
}
public String getJarName()
{
return jarName;
}
public void setJarName(String jarName)
{
this.jarName = jarName;
}
public String getClassName()
{
return className;
}
public void setClassName(String className)
{
this.className = className;
}
}
}
jar包冲突解决方法的更多相关文章
- tomcat web工程 jar包冲突解决方法
目前在部署工程时,遇到了一个问题,报错信息如下: See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet ...
- 【Maven】【IDEA】在idea中开发web项目,解决maven的jar包冲突的方法
在idea中开发web项目,解决maven的jar包冲突的方法 第一步: 先对项目进行 clean ,再进行install 第二步: 出现NoSuchMethodException,ClassNotF ...
- jar包冲突排解方法(sbt)
jar包依赖冲突,版本不兼容会导致各种各样的问题.这里推荐一款sbt插件用于查找项目中的jar包依赖关系,通过该插件可以轻松的看出某个jar包依赖哪些jar,以及某个jar被哪些jar所依赖.此外该插 ...
- Eclipse笔记-sun.misc.BASE64Encoder找不到jar包的解决方法
从SVN检出新项目,在Eclipse中报错如下: 转: Eclipse笔记-sun.misc.BASE64Encoder找不到jar包的解决方法 2018-01-04 00:36:20 雨临Lewis ...
- xml-apis.jar getTextContent() jar包冲突解决(getTextContent()方法无法找到)
1.引用包: import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NodeList; 2.方法中应用: ...
- Android 第三方库导致jar包冲突解决办法
这几天的任务是将mapbox的工程合到程序中去,但是合并过程却出现了问题 合并方法: 在app的build.gradle中添加 dependencies { compile ('com.mapbox. ...
- 曹工杂谈:一例简单的Jar包冲突解决示例
Jar包冲突的相关文章: 了不得,我可能发现了Jar 包冲突的秘密 一.前言 jar包冲突分多种,简单理解来说,就是同package且同名的类在多个jar包内出现,如果两个jar包在同一个clas ...
- jar包冲突解决
背景: 新需求需要引入新jar包,引入后发现本地启动没有报错,发到测试环境提示某个bean无法创建,nested exception is java.lang.VerifyError: Bad typ ...
- java 包冲突解决方法
1.诊断包冲突 java.lang.NoSuchMethodError: org.apache.commons.io.output.DeferredFileOutputStream.<init& ...
随机推荐
- 机器学习框架Scikit Learn的学习
一 安装 安装pip 代码如下:# wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=83 ...
- SCAU 07校赛 10317 Fans of Footbal Teams
10317 Fans of Footbal Teams 时间限制:1000MS 内存限制:65535K 题型: 编程题 语言: 无限制 Description Two famous footba ...
- git使用中遇到的常见问题
.gitignore 中添加的文件不能被忽略掉 这是因为我们误解了 .gitignore 文件的用途,该文件只能作用于 Untracked Files,也就是那些从来没有被 Git 记录过的文件(自添 ...
- 修改Map中确定key对应的value问题
今天在码代码的时候出现一个没有预料的问题: 先看下面的代码: public static void main(String[] args) { String[] files=new String[]{ ...
- JDBC学习笔记(4)——PreparedStatement的使用
PreparedStatement public interface PreparedStatement extends Statement;可以看到PreparedStatement是Stateme ...
- 【转】Xcode 插件优缺点对比(推荐 20 款插件)
[转自]http://www.cnblogs.com/dsxniubility/p/5099191.html 1.Alcatraz 类似于管理第三方库的cocoapods,管理插件也有个Alcatra ...
- << 移位运算
/** * The maximum capacity, used if a higher value is implicitly specified * by either of the constr ...
- C#下内存管理--垃圾收集
章节安排 内存管理简介 垃圾回收机制 性能问题 C#下非托管资源的处理 要强调的几点 References 内存管理简介 对于任何一种编程语言,内存管理都是不得不提很重要的一块内容,但可惜的是目前为止 ...
- iOS类别(Category)
iOS类别(Category)与扩展(Extension) 苹果的官方文档 Category在iOS开发中使用非常频繁.尤其是在为系统类进行拓展的时候,我们可以不用继承系统类,直接给系统类添加方法,最 ...
- SessionFactory、HibernateTemplate、HibernateDaoSupport之间的关系说明
在接触HibernateTemplate之前,我们知道,在对数据库进行CRUD操作之前,需要开启session.transaction等等.在hibernate学习过程中,我们知道了,得到sessio ...