我认为为自己编写一个工具并不难。
您可以使用System.getProperty("java.class.path")获取类路径条目。
然后遍历列出的jar、zip或目录,并收集有关类的所有信息,找出可能会引起麻烦的类。
这项任务最多需要1到2天时间。然后,您可以直接在应用程序中加载此类并生成报告。
可能java.class.path属性无法显示所有类,如果在一些具有复杂自定义类加载的基础设施中运行(例如,我曾经看到过一个从LDAP加载类的应用程序),但它肯定适用于大多数情况。
这是一个您可能会发现有用的工具,我自己从未使用过,但请尝试并告诉我们结果。
http://www.jgoodies.com/freeware/jpathreport/features.html
如果您想创建自己的工具,以下是我在Windows机器上使用的相同shell脚本代码,但当有大量jar文件时运行速度更快。您可以使用并修改它,以便不再递归地遍历目录,而是读取类路径并比较.class时间属性。如果需要,可以子类化Command类,我正在考虑“find”选项的-execute选项。这是我的自己的代码,所以它并不意味着要"生产就绪",只是为了完成工作。
import java.io.*;
import java.util.zip.*;
public class ListZipContent{
public static void main( String [] args ) throws IOException {
System.out.println( "start " + new java.util.Date() );
String pattern = args.length == 1 ? args[0] : "OracleDriver.class";
File file = new File(".");
FileFilter fileFilter = new FileFilter(){
public boolean accept( File file ){
return file.isDirectory() || file.getName().endsWith( "jar" );
}
};
Command command = new Command( pattern );
executeRecursively( command, file, fileFilter );
System.out.println( "finish " + new java.util.Date() );
}
private static void executeRecursively( Command command, File dir , FileFilter filter ) throws IOException {
if( !dir.isDirectory() ){
System.out.println( "not a directory " + dir );
return;
}
for( File file : dir.listFiles( filter ) ){
if( file.isDirectory()){
executeRecursively( command,file , filter );
}else{
command.executeOn( file );
}
}
}
}
class Command {
private String pattern;
public Command( String pattern ){
this.pattern = pattern;
}
public void executeOn( File file ) throws IOException {
if( pattern == null ) {
System.out.println( "Pattern is null ");
return;
}
String fileName = file.getName();
boolean jarNameAlreadyPrinted = false;
ZipInputStream zis = null;
try{
zis = new ZipInputStream( new FileInputStream( file ) );
ZipEntry ze;
while(( ze = zis.getNextEntry() ) != null ) {
if( ze.getName().endsWith( pattern )){
if( !jarNameAlreadyPrinted ){
System.out.println("Contents of: " + file.getCanonicalPath() );
jarNameAlreadyPrinted = true;
}
System.out.println( " " + ze.getName() );
}
zis.closeEntry();
}
}finally{
if( zis != null ) try {
zis.close();
}catch( Throwable t ){}
}
}
}
我希望这可以帮到你。