- 浏览: 339441 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
javer:
xiaoxuan1130 写道 ...
解决 - java.lang.OutOfMemoryError: unable to create new native thread -
xiaoxuan1130:
解决 - java.lang.OutOfMemoryError: unable to create new native thread -
wtnbmy_aaaeau:
class Solution {public: int ...
leetcode : Best Time to Buy and Sell Stock -
williamxww:
mark
解决 - java.lang.OutOfMemoryError: unable to create new native thread -
zxjlwt:
学习了,非常好。http://surenpi.com
解决 - java.lang.OutOfMemoryError: unable to create new native thread
最近因为因为web容器升级,而容器自带了很多jar,发现和应用中的jar有冲突(相同的类,不同的版本),导致出现NoSuchMethon异常什么的。需求来了,需要比较两个目录下有那些相同的类。这个需求前人已经写烂了,可上网搜索一时找不到合适的,就再写了一遍,并作下记录,方便后来人和将来的自己再用。
不多说,上代码(一次性代码,1小时搞定,如有编程风格问题,敬请谅解):
package com.mikegu.tools.jardiff; import java.io.File; import java.io.IOException; /** * 启动入口类 * * @author haiquan.guhq */ public class JarDiffMain { /** * 输入要比较的两个目录,目录下包含jar,结果输出到控制台。 */ public static void main(String[] args) throws IOException { if (args.length != 2) { System.out.println("please input two compare dirs"); System.exit(1); } String firstInputPath = args[0]; String secondInputPath = args[1]; File file = new File(firstInputPath); File[] listFiles = file.listFiles(); for (File oneFile : listFiles) { if (oneFile.isFile() && oneFile.getAbsolutePath().endsWith(".jar")) { String jarName = oneFile.getName(); ZipDecompression.decompression(oneFile.getAbsolutePath(), firstInputPath + "/tmp/" + jarName); // 解压 ClassNameFinder.find(jarName, firstInputPath + "/tmp/" + jarName, 1); // 查找 } } file = new File(secondInputPath); listFiles = file.listFiles(); for (File oneFile : listFiles) { if (oneFile.isFile() && oneFile.getAbsolutePath().endsWith(".jar")) { String jarName = oneFile.getName(); ZipDecompression.decompression(oneFile.getAbsolutePath(), secondInputPath + "/tmp/" + jarName); ClassNameFinder.find(jarName, secondInputPath + "/tmp/" + jarName, 2); } } ClassNameFinder.compare(); } }
package com.mikegu.tools.jardiff; import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.TreeMap; /** * 搜索和比较相同的类 */ public class ClassNameFinder { private static Map<String, List<ClassInfosDO>> firstMap = new HashMap<String, List<ClassInfosDO>>(); private static Map<String, List<ClassInfosDO>> secondMap = new HashMap<String, List<ClassInfosDO>>(); public static void find(String jarName, String path, int order) { List<String> allClassName = new ArrayList<String>(); //根据路径取得全类 getAllClassName(path, allClassName, path.length() + 1); if (allClassName != null) { for (String one : allClassName) { ClassInfosDO classInfosDO = new ClassInfosDO(one, jarName); List<ClassInfosDO> list = getOrderMap(order).get(one); if (list == null) { List<ClassInfosDO> arrayList = new ArrayList<ClassInfosDO>(); arrayList.add(classInfosDO); getOrderMap(order).put(one, arrayList); } else { list.add(classInfosDO); } } } } public static void compare() { Set<String> keySet = firstMap.keySet(); List<String> keyList = new ArrayList<String>(); keyList.addAll(keySet); Collections.sort(keyList); Map<String, List<String>> jarViewResult = new TreeMap<String, List<String>>(); List<String> classViewResult = new ArrayList<String>(); for (String fullClassName : keyList) { List<ClassInfosDO> list = secondMap.get(fullClassName); if (list != null) { //目录1 StringBuffer input1SB = new StringBuffer(); List<ClassInfosDO> value = firstMap.get(fullClassName); for (ClassInfosDO oneClassInfosDO : value) { input1SB.append(" " + oneClassInfosDO.getJarName() + ","); } //目录2 StringBuffer input2SB = new StringBuffer(); for (ClassInfosDO oneClassInfosDO : list) { input2SB.append(" " + oneClassInfosDO.getJarName() + ","); } classViewResult.add(fullClassName + "\tInput1: " + input1SB.toString() + "\t input2: " + input2SB.toString()); String jarKey = input1SB.toString() + " vs " + input2SB.toString(); if (jarViewResult.get(jarKey) != null) { jarViewResult.get(jarKey).add(fullClassName); } else { List<String> classes = new ArrayList<String>(); classes.add(fullClassName); jarViewResult.put(jarKey, classes); } } } writeResult(jarViewResult, classViewResult); } /** * 从jar的纬度和class的纬度分别输出结果 */ private static void writeResult(Map<String, List<String>> jarViewResult, List<String> classViewResult) { System.out.println("View From jar start....."); System.out.println("Total conflict jar num is " + jarViewResult.size()); Set<Entry<String, List<String>>> entrySet = jarViewResult.entrySet(); for (Entry<String, List<String>> one : entrySet) { String key = one.getKey(); System.out.println("conflict jar name is" + key); for (String oneClassName : one.getValue()) { System.out.println("\t\t" + oneClassName); } System.out.println(); } System.out.println("View From jar end!!!!"); System.out.println("View From class start....."); System.out.println("Total conflict class num is " + classViewResult.size()); for (String abc : classViewResult) { System.out.println(abc); } System.out.println("View From class end!!!!"); } public static Map<String, List<ClassInfosDO>> getOrderMap(int order) { if (order == 1) { return firstMap; } else { return secondMap; } } public static void getAllClassName(String dir, List<String> allClassName, int length) { File file = new File(dir); File[] listFiles = file.listFiles(); if (listFiles == null || listFiles.length == 0) { return; } for (File oneFile : listFiles) { String absolutePath = oneFile.getAbsolutePath(); if (oneFile.isDirectory()) { getAllClassName(absolutePath, allClassName, length); } else { if (absolutePath.endsWith(".class")) { allClassName.add(absolutePath.substring(length)); } } } } // public static void main(String[] args) { // List<String> allClassName = new ArrayList<String>(); // getAllClassName("/tmp/1", allClassName, "/tmp/1".length() + 1); // System.out.println(allClassName); // System.out.println(allClassName.size()); // // } }
package com.mikegu.tools.jardiff; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class ZipDecompression { // public static void main(String[] args) throws IOException { // String fileName = "toolkit.common.lang-1.0-sources.jar"; // decompression("C:/" + fileName, "C:/test"); // } public static void decompression(String zipFile, String destination) throws IOException { ZipFile zip; try { zip = new ZipFile(zipFile); } catch (IOException e) { System.out.println("error name " + zipFile); throw e; } Enumeration en = zip.entries(); ZipEntry entry = null; byte[] buffer = new byte[8192]; int length = -1; InputStream input = null; BufferedOutputStream bos = null; File file = null; while (en.hasMoreElements()) { entry = (ZipEntry) en.nextElement(); if (entry.isDirectory()) { continue; } input = zip.getInputStream(entry); file = new File(destination, entry.getName()); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } bos = new BufferedOutputStream(new FileOutputStream(file)); while (true) { length = input.read(buffer); if (length == -1) break; bos.write(buffer, 0, length); } bos.close(); input.close(); } zip.close(); } }
package com.mikegu.tools.jardiff; /** * 类信息DO */ public class ClassInfosDO { private String classFullName; private String jarName; /** * @param classFullName * @param jarName */ public ClassInfosDO(String classFullName, String jarName) { this.classFullName = classFullName; this.jarName = jarName; } /** * @return the classFullName */ public String getClassFullName() { return classFullName; } /** * @param classFullName the classFullName to set */ public void setClassFullName(String classFullName) { this.classFullName = classFullName; } /** * @return the jarName */ public String getJarName() { return jarName; } /** * @param jarName the jarName to set */ public void setJarName(String jarName) { this.jarName = jarName; } }
发表评论
-
论坛图片爬虫的一种实现
2011-05-14 17:35 30961背景 经常上贴图的论坛(Discuz!),每次打开 ... -
Visitor Design Pattern(访问者设计模式)
2011-02-10 21:44 2716Visitor Design Pattern(访问者设计模式 ... -
大对象导致JVM Crash (Jboss) 分析及解决 - JDK 已知bug
2010-11-01 19:32 9398最近在一个项目中,web 应用跑一段时间后, JBoss J ... -
一场内存异常的虚惊
2010-08-19 11:35 2202经过: 对一个应用作性能测试,发现内存曲线很恐怖,内存不 ... -
解决 - java.lang.OutOfMemoryError: unable to create new native thread
2010-03-23 23:11 165535工作中碰到过这个问题好几次了,觉得有必要总结一下,所以有 ... -
Diagnosing Leaks in Native Code
2008-06-01 14:26 1682本文摘自sun.com网站分析Diagnosing ... -
java GC 内存变化浅析
2008-06-01 14:29 1567在指定jvm的运行参数-Xms1024m -Xmx102 ... -
windows linux jdk配置
2008-06-01 14:34 2075Windows 一个jdk的设置: CLASSPA ... -
JDK中LinkedBlockingQueue 内存泄漏问题
2008-06-01 14:38 11066昨天晚上跑的程序,今早来的时候发现抛了个Java Heap: ... -
Swing中 设置整个Application的字体
2008-06-01 15:05 1675一般通过UIManager去设置各个参数。 用这个类: ... -
Java Performance - When 4294967296 bytes of address space isn't enough
2008-06-01 15:33 1755the more memory you give to the ... -
如何分析Java虚拟机死锁
2008-06-01 15:38 8662英文资料: Thread Dump and Concur ... -
剖析JVM 内存系列------之JVM的内存机制介绍(理论篇)
2009-03-22 20:42 3459本文分为两个部分: 1,JVM specification ...
相关推荐
解决jar包冲突的工具类jarjar-1.4.rar,jar包冲突解决方法,解决jar与jar冲突,jar与aar冲突,不想删除任何一个包,只能修改其中一个jar包包名即可解决,解决方法详细请看这篇文章: ...
检查jar包冲突检查jar包冲突检查jar包冲突检查jar包冲突
检测工具 jar包冲突
在websphere8.5 下部署含有CXFwebservice的war包无法正常启动,...归根结底原因不是找不到类,而是发布后war下的jar与websphere自身平台下的jar冲突了,要解决此问题就要通过在websphere下建立共享库来根除,可参考附件
压缩包里面有myself工程。里面只有一个类。可以自己创建两个版本的myself的jar包,然后测试osgi解决jar包冲突。
该文档用于解决在websphere application server 服务部署程序过程中会出现jar包冲突问题
打开exe程序,选择项目jar包路径,就可以检测冲突的jar包了。
构建maven工程时pom.xml中引入依赖时有红色字体,setting处理了,也将jar包的版本号都试了一遍,还是没解决,后来请教大牛,原来是没连网,maven工程加载了一部分jar包,连网之后自动下载的jar包跟之前的冲突,用这...
jar包冲突检测工具。使用方法,将需要检测的多个jar包放在同一路径下,打开工具一键检测生成冲突报告。
SSH整合jar包,彻底解决集成jar包冲突问题,内涵绝大部分常用框架的jar包和一些常用jar包
Hibernate+Struts jar包冲突问题
在tomcat下部署成功,迁移到weblogic下,报错,一般都是配置和jar包问题,配置问题开发根据报错能解决,jar冲突比较烦人,这里给出了解决方案。
如何在WebSphere中解决jar包冲突.doc
将 juel.jar, juel-engine.jar, juel-impl.jar 这三个包复制到tomcat6下 lib/ 中,并删除原来的el-api.jar,切记还要把工程中 WEB-INF\lib 下的 juel.jar, juel-engine.jar, juel-impl.jar 删除,不然还是要冲突。...
遇到jar包冲突时,需要找某个class文件在哪几个jar包中,可以用这个工具进行查找,很快速方便的
故重新打包 XmlSchema-1.1.jar 源码修改原类径的方法来重新打包避免冲突 源码放在javas.rar文件夹中 org.codehaus.xfire.wsdl11.parser.SchemaInfo org.codehaus.xfire.wsdl11.parser.WSDLServiceBuilder org....
故重新打包 XmlSchema-1.1.jar 源码修改原类径的方法来重新打包避免冲突 org.codehaus.xfire.wsdl11.parser.SchemaInfo org.codehaus.xfire.wsdl11.parser.WSDLServiceBuilder org.codehaus.xfire.wsdl11....
Maven的Jar包冲突问题,经常出现的场景为: 本地运行报NoSuchMethodError,ClassNotFoundException。明明在依赖里有这个Jar包啊。怎么运行不了!? 项目中明明定义着某个jar包版本为2.0.2,怎么打包之后变成2.5.0了...