jar包检索

本文介绍了一个Java小工具,用于查找项目中的所有jar包,详细解析并记录每个jar中.class文件,便于代码内容分析。通过实例展示了如何遍历目录和jar文件,提取.class文件名并写入文本文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目组需要将代码中所有的jar包检索出来,并对jar中内容进行分析,特开发出这个java小工具,同样这也是一个模板,可以按照需要修改任何想要检索的文件!想要了解对jar中内容分析的代码如何编写可以给我留言欧。

import java.io.*;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class FindClass{
	private static int num = 0;
	private static File projectRoot = new File("文件路径");
	private static void main(String[] args) throws IOException {
		findSpecifiedClassInJar(projectRoot);
	}
	public static boolean findClassInJar(File file) throws IOException {
		if(file.isDirectory()){
			for(File subFile : file.listFiles()){
				if(findClassInJar(subFile)){
					return true;
				}
			}
		}else{
			if(file.getAbsolutePath().endsWith(".jar")){
				try{
					JarFile jarFile = new JarFile(file);
					Enumeration<JarEntry> enu = jarFile.entries();
					System.out.println(file.getName());
					num++;
					while(enu.hasMoreElements()){
						JarEntry jarEntry = enu.nextElment();
						String entry = jarEntry.getName();
						if(entry.endsWith(".class")){
							entry = entry.replaceAll("/",".").substring(0);
							System.out.println(entry);
							FileWriter fileWriter = new FileWriter("class.txt",true);
							BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
							bufferedWriter.write(entry);
							bufferedWriter.newLine();
							bufferedWriter.close();
						}
					}
				}catch (Exception e){
					
				}
			}
		}
		return false;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值