package com.yun70;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class myClassLoader extends ClassLoader
{
public static void main(String[] args)
{
StringBuffer sb = new StringBuffer();
try
{
String warpath = "D:\\test3.war";
//String warpath = "D:\\spring-aop-3.0.5.RELEASE.jar";
JarFile jarFile = new JarFile(warpath);
JarEntry jarEntry = jarFile.getJarEntry("WEB-INF/web.xml");
if(null != jarEntry)
{
System.out.println("--web.xml:"+jarEntry.getName());
}
else
{
System.out.println("----不是war包...");
return;
}
InputStream jarEntryInputStream = jarFile.getInputStream(jarEntry);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(jarEntryInputStream));
String readLine =null;
while((readLine = bufferedReader.readLine())!=null)
{
sb.append(readLine);
sb.append("\r\n");
}
bufferedReader.close();
jarEntryInputStream.close();
System.out.println("--sb: " + sb.toString());
}
catch(Exception e)
{
e.printStackTrace();
}
}
}