在一大群罐子里找到一个特定的类

时间:2011-04-13 16:00:20

标签: java

在不同文件夹(窗口)中的大型jar文件组中查找类的推荐方法是什么? 目前我使用editplus搜索看起来很棒。但也许我错过了一个更好的方法? 谢谢。
修改 我需要以编程方式找到它。

5 个答案:

答案 0 :(得分:1)

jars=/opt/java/jre/lib/ext/mail.jar:/opt/java/jre/lib/ext/postgresql.jar
for jar in $(echo $jars | sed 's/:/ /g'); do 
    jar -tf $jar | grep Driver && echo $jar
done

对于Windows,请替换:with;在“罐子” - 变量和sed命令。 sed是gnu-tools的一部分 - 它们有一个二进制win32端口,它包含grep,sed,sh.exe和更多有用的工具。

将驱动程序替换为%1,使其成为可参数化的脚本。

答案 1 :(得分:1)

我会使用

等在线搜索工具

答案 2 :(得分:1)

尝试cf.jar

Usage:

   java  -jar  cf.jar  SEARCH  [DIRECTORY]  [OPTIONS]...

Searches all JAR files in the current directory and its sub-directories for
entries matching the SEARCH argument. If DIRECTORY is provided, searching will
be done in that location instead of the current directory.

SEARCH:

  A search string containing the class name (entry name). Wild card (*) is
  supported. Package separator can be either of `/', `\' or `.'.

  Examples:

    java.lang.String
    java/util/ArrayList
    java/lang/Str*B*er

  If non ".class" entries also need to be searched, option -a (--all-types)
  should be specified. Please see the OPTIONS section for a more detailed
  explanation.

DIRECTORY:

  If this is not provided, current directory and all its sub-directories will
  be used for performing the search. However, if this argument is provided,
  the same and its sub-directories will be used as the location to fetch JAR
  files from.

  If a recursive scan is not needed, option -s (--shallow) can be specified.

OPTIONS:

  -h          --help
                   Shows this help
  -o [path]   --redirect-output
                   Redirect output to a file path supplied.
  -x [x1,x2]  --archive-extensions
                   Extensions in addition to the default ".jar". Comma or space
                   separated list accepted.
  -i          --insensitive-case
                   Case insensitive search.
  -q          --quiet
                   Silent search without the progress bar animation.
  -a          --all-types
                   Removes the filtering on ".class" types so that other types
                   such as ".properties", ".xml", etc can also be searched for.
  -s          --shallow
                   Performs a shallow search. Doesn't recurse.

Examples:

   java  -jar  cf.jar  org/apache/log4j/Level  D:\Frameworks
   java  -jar  cf.jar  *OracleDriver  C:\oracle -x jar,zip
   java  -jar  cf.jar  messages.properties  D:\IBM\WebSphere -a -x jar,war,ear
   java  -jar  cf.jar  util.*  D:\Java -i -q

答案 3 :(得分:1)

由于您正在使用IntelliJ,您可以导航到相关课程(转至 - >类...),然后在项目视图中显示它(Alt-F1 - >项目视图)。

答案 4 :(得分:0)

如果你已经有了,我建议使用JD GUI

只需打开罐子(将所有罐子拖放到UI中),然后按CTRL + SHIFT + T.输入类名,您将获得该类所在的所有罐子的列表。

如果你知道班级名称,而不是jar,请使用搜索maven工具。 http://search.maven.org/

对于商业客户,我通常使用maven。我设置了一个内部nexus存储库,然后使用它的搜索。

如果项目是在Eclipse 中设置的,请使用CTRL + SHIFT + T并键入类名

如果项目在IntellJ 中,请使用CTRL + N并输入类名