使用命令行快速找出class文件所在的jar文件
程序员文章站
2024-03-24 11:03:40
...
由于jar命令去查找class文件速度比较慢,我个人尝试使用7z.exe,7z.dll,结合批处理,效果非常不错。
请看示例:
for%iin(dir/b/s*.jar)do7zl%i|findstrXDatabase.class
结果:
- D:\shared\xsql>for%iin(dir/b/s*.jar)do7zl%i|findstrXDatabase.class
- D:\shared\xsql>7zldir/b/s|findstrXDatabase.class
- D:\shared\xsql>7zldb2jcc.jar|findstrXDatabase.class
- D:\shared\xsql>7zldb2jcc_license_cu.jar|findstrXDatabase.class
- D:\shared\xsql>7zljconn3.jar|findstrXDatabase.class
- D:\shared\xsql>7zljodbc.jar|findstrXDatabase.class
- D:\shared\xsql>7zljTDS3.jar|findstrXDatabase.class
- D:\shared\xsql>7zlmlscript.jar|findstrXDatabase.class
- D:\shared\xsql>7zlmsbase.jar|findstrXDatabase.class
- D:\shared\xsql>7zlmssqlserver.jar|findstrXDatabase.class
- D:\shared\xsql>7zlmsutil.jar|findstrXDatabase.class
- D:\shared\xsql>7zlmysql-connector-java-5.1.6-bin.jar|findstrXDatabase.class
- D:\shared\xsql>7zlojdbc14.jar|findstrXDatabase.class
- D:\shared\xsql>7zlpostgresql-8.4-701.jdbc4.jar|findstrXDatabase.class
- D:\shared\xsql>7zlsqlite.jar|findstrXDatabase.class
- D:\shared\xsql>7zlsqlitejdbc-v056-zentus.jar|findstrXDatabase.class
- D:\shared\xsql>7zlsqljdbc.jar|findstrXDatabase.class
- D:\shared\xsql>7zlULjDatabaseTransfer.jar|findstrXDatabase.class
- D:\shared\xsql>7zlUltraLiteJ.jar|findstrXDatabase.class
- D:\shared\xsql>7zlUltraLiteJ12.jar|findstrXDatabase.class
- [b]D:\shared\xsql>7zlxsql.jar|findstrXDatabase.class
- 2010-12-2421:05:40.....3086314443[/b]com\sean\db\XDatabase.class
最末一行展示的是最终结果。
将上述逻辑写成批处理:
- @echooff
- SETLOCAL
- setWHICH_CLASS=%1
- echoWHICH_CLASS=%WHICH_CLASS%
- for/F%%iin('dir/A:-D/S/B*.jar')do7zl%%i|findstr%WHICH_CLASS%&&echo%WHICH_CLASS%foundin:"%%i"
- echo"Finishedclassfinding..."
- echo"======================================"
- ENDLOCAL
运行一下命令:
findclass com\\sybase\\afx\\util\\StringUtil.class
WHICH_CLASS=com\\sybase\\afx\\util\\StringUtil.class
2012-02-27 13:14:36 ..... 15230 5915 com\sybase\afx\util\StringUtil.class
com\\sybase\\afx\\util\\StringUtil.class found in: "U:\target\lib\ext\sup-client.jar"
2012-02-27 13:14:36 ..... 15230 5915 com\sybase\afx\util\StringUtil.class
com\\sybase\\afx\\util\\StringUtil.class found in: "U:\target\lib\ext\sup-server-rt.jar"
"Finished class finding..."
"======================================"
很容易得到最终结果。如果时间充分,我们甚至可以修改7z的源码,让它直接列出文件的全路径,那样,直接使用7z就可以找到最终文件了。