欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用命令行快速找出class文件所在的jar文件

程序员文章站 2024-03-24 11:03:40
...

由于jar命令去查找class文件速度比较慢,我个人尝试使用7z.exe,7z.dll,结合批处理,效果非常不错。

请看示例:

for%iin(dir/b/s*.jar)do7zl%i|findstrXDatabase.class

结果:

  1. D:\shared\xsql>for%iin(dir/b/s*.jar)do7zl%i|findstrXDatabase.class
  2. D:\shared\xsql>7zldir/b/s|findstrXDatabase.class
  3. D:\shared\xsql>7zldb2jcc.jar|findstrXDatabase.class
  4. D:\shared\xsql>7zldb2jcc_license_cu.jar|findstrXDatabase.class
  5. D:\shared\xsql>7zljconn3.jar|findstrXDatabase.class
  6. D:\shared\xsql>7zljodbc.jar|findstrXDatabase.class
  7. D:\shared\xsql>7zljTDS3.jar|findstrXDatabase.class
  8. D:\shared\xsql>7zlmlscript.jar|findstrXDatabase.class
  9. D:\shared\xsql>7zlmsbase.jar|findstrXDatabase.class
  10. D:\shared\xsql>7zlmssqlserver.jar|findstrXDatabase.class
  11. D:\shared\xsql>7zlmsutil.jar|findstrXDatabase.class
  12. D:\shared\xsql>7zlmysql-connector-java-5.1.6-bin.jar|findstrXDatabase.class
  13. D:\shared\xsql>7zlojdbc14.jar|findstrXDatabase.class
  14. D:\shared\xsql>7zlpostgresql-8.4-701.jdbc4.jar|findstrXDatabase.class
  15. D:\shared\xsql>7zlsqlite.jar|findstrXDatabase.class
  16. D:\shared\xsql>7zlsqlitejdbc-v056-zentus.jar|findstrXDatabase.class
  17. D:\shared\xsql>7zlsqljdbc.jar|findstrXDatabase.class
  18. D:\shared\xsql>7zlULjDatabaseTransfer.jar|findstrXDatabase.class
  19. D:\shared\xsql>7zlUltraLiteJ.jar|findstrXDatabase.class
  20. D:\shared\xsql>7zlUltraLiteJ12.jar|findstrXDatabase.class
  21. [b]D:\shared\xsql>7zlxsql.jar|findstrXDatabase.class
  22. 2010-12-2421:05:40.....3086314443[/b]com\sean\db\XDatabase.class

最末一行展示的是最终结果。

将上述逻辑写成批处理:

  1. @echooff
  2. SETLOCAL
  3. setWHICH_CLASS=%1
  4. echoWHICH_CLASS=%WHICH_CLASS%
  5. for/F%%iin('dir/A:-D/S/B*.jar')do7zl%%i|findstr%WHICH_CLASS%&&echo%WHICH_CLASS%foundin:"%%i"
  6. echo"Finishedclassfinding..."
  7. echo"======================================"
  8. 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就可以找到最终文件了。