获取jar包中的类名的类,用以检测不同jar包内是否存在相同名字的类,再次记录备忘。
package cn.letterme.Jar;
import java.io.IOException;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
/**
* 获取jar包中的所有类
* @author zzz@letterme.cn
* @date 2015年1月25日
* @version V1.0.0 beta
*/
public class GetClass
{
public static void main(String[] args)
{
JarFile jfile = null;
try
{
jfile = new JarFile("D:\\cn.letterme\\cn.letterme.lib\\servlet-api.jar");
}
catch (IOException e)
{
e.printStackTrace();
}
Enumeration<JarEntry> files = jfile.entries();
while (files.hasMoreElements())
{
JarEntry entry = (JarEntry) files.nextElement();
if (entry.getName().endsWith(".class"))
{
System.out.println(entry.getName());
}
}
}
}
注:转载请注明出处~~