import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.jar.JarFile;
/**
*
*/
/**
* @author Administrator
*
*/
public class FindJar {
private String findpath="D:\\技术\\tiles-test-3.0.1\\WEB-INF\\lib";
private String classpath="org.apache.tiles.web.util.TilesDispatchServlet";
/**
* @param args
* @throws IOException
*/
public void findJarbyClass() throws IOException{
File jarPath = new File(findpath);
File[] jarfiles = jarPath.listFiles(new FilenameFilter(){
@Override
public boolean accept(File arg0, String name) {
// TODO Auto-generated method stub
if(name.endsWith(".jar"))
return true;
else
return false;
}
});
for(File file : jarfiles){
JarFile jar = new JarFile(file);
URL url = new URL("jar:file:"+jar.getName()+"!/"+classpath.replace(".", "/")+".class");
JarURLConnection jarConnection = (JarURLConnection)url.openConnection();
try{
jarConnection.getJarEntry();
System.out.println(jar.getName());
break;
}catch(FileNotFoundException e){
continue;
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
FindJar findjar = new FindJar();
try {
findjar.findJarbyClass();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
根据class查找jar源码样例
最新推荐文章于 2022-03-22 19:54:53 发布