⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchinjar.java

📁 当jar包中某个class重复的时候
💻 JAVA
字号:
import java.util.*;   
import java.io.*;   
   
public class SearchInJar   
{   
    public static int count = 0;   
   
    public SearchInJar(){}   
   
    static public void main(String[] args)   
    {   
    	/*
        if (args.length < 2)   
        {   
            showHowToUsage();   
            return;   
        }  
        */
    	String className = "IBMSessionListener";		//要查询的class,要带包名的类名
    	String libPath="E:/users/admin/Desktop/lib";						//所要查找的JAR包的目录
    	
        String absoluteclassname = className.replace('.', '/') + ".class";   
   
        System.out.println("Find class [" + className + "] in Path [" + libPath   
                + "] Results:");   
        FindClassInLocalSystem(libPath, absoluteclassname);   
        if (SearchInJar.count == 0)   
        {   
            System.out.println("Error:Can't Find Such Jar File!");   
        }   
        System.out   
                .println("Find Process Ended! Total Results:" + SearchInJar.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." + ++SearchInJar.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");   
    }   
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -