由於jar命令去查找class文件速度比較慢,我個人嘗試使用7z.exe,7z.dll,結合批處理,效果非常不錯。
請看示例:
for %i in (dir/b/s *.jar) do 7z l %i | findstr XDatabase.class
結果:
- D:\shared\xsql>for %i in (dir/b/s *.jar) do 7z l %i |findstr XDatabase.class
- D:\shared\xsql>7z l dir/b/s | findstr XDatabase.class
- D:\shared\xsql>7z l db2jcc.jar | findstr XDatabase.class
- D:\shared\xsql>7z l db2jcc_license_cu.jar | findstr XDatabase.class
- D:\shared\xsql>7z l jconn3.jar | findstr XDatabase.class
- D:\shared\xsql>7z l jodbc.jar | findstr XDatabase.class
- D:\shared\xsql>7z l jTDS3.jar | findstr XDatabase.class
- D:\shared\xsql>7z l mlscript.jar | findstr XDatabase.class
- D:\shared\xsql>7z l msbase.jar | findstr XDatabase.class
- D:\shared\xsql>7z l mssqlserver.jar | findstr XDatabase.class
- D:\shared\xsql>7z l msutil.jar | findstr XDatabase.class
- D:\shared\xsql>7z l MySQL-connector-Java-5.1.6-bin.jar | findstr XDatabase.class
- D:\shared\xsql>7z l ojdbc14.jar | findstr XDatabase.class
- D:\shared\xsql>7z l postgresql-8.4-701.jdbc4.jar | findstr XDatabase.class
- D:\shared\xsql>7z l sqlite.jar | findstr XDatabase.class
- D:\shared\xsql>7z l sqlitejdbc-v056-zentus.jar | findstr XDatabase.class
- D:\shared\xsql>7z l sqljdbc.jar | findstr XDatabase.class
- D:\shared\xsql>7z l ULjDatabaseTransfer.jar | findstr XDatabase.class
- D:\shared\xsql>7z l UltraLiteJ.jar | findstr XDatabase.class
- D:\shared\xsql>7z l UltraLiteJ12.jar | findstr XDatabase.class
- [b]D:\shared\xsql>7z l xsql.jar | findstr XDatabase.class
- 2010-12-24 21:05:40 ..... 30863 14443 [/b]com\sean\db\XDatabase.class
最末一行展示的是最終結果。
將上述邏輯寫成批處理:
- @echo off
- SETLOCAL
- set WHICH_CLASS=%1
- echo WHICH_CLASS=%WHICH_CLASS%
- for /F %%i in ('dir /A:-D /S /B *.jar') do 7z l %%i | findstr %WHICH_CLASS% && echo %WHICH_CLASS% found in: "%%i"
- echo "Finished class finding..."
- 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就可以找到最終文件了。