找到一个jar文件给出类名? [英] Find a jar file given the class name?

查看:84
本文介绍了找到一个jar文件给出类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Java开发人员来说,这必须是一个非常基本的问题,但是给定一个类名?,找到合适的 jar文件的最佳方法是什么? b
$ b

例如,给定 com.ibm.websphere.security.auth.WSSubject 你怎么跟踪适当的jar文件? (google不是我要找的答案!)



java文档不提供任何提示的jar文件,显然jar文件的名称本身不提供任何线索。



必须有一个'搜索当地的罐子或某种自动解决依赖关系,在java世界的伎俩。理想情况下,我正在寻找官方的方式来做到这一点。我碰巧在没有cygwin的Windows机器上。

解决方案

将其另存为findclass.sh(或任何),将其放在您的路径并使其可执行:

 #!/ bin / sh 
找到$ 1-name*。 jar-exec sh -c'jar -tf {} | grep -H --label {}'$ 2''\;

第一个参数是递归搜索的目录,第二个参数是一个正则表达式(通常只是一个简单的类名称)来搜索。

  $ findclass.sh。 WSSubject 

脚本依赖于jar命令的-t选项(其中列出了内容)和greps每个目录,标记与发现JAR文件路径的任何匹配。


This must be a very basic question for Java developers, but what is the best way to find the appropriate jar file given a class name?

For example, given "com.ibm.websphere.security.auth.WSSubject", how do you track down the appropriate jar file? ("google" is not the answer I'm looking for!)

The java docs do not give any hint of the jar file, and obviously the names of the jar files themselves offer no clue.

There must be a 'search local jars', or some sort of 'auto-resolve dependencies', trick in the java world. Ideally, I'm looking for the 'official' way to do this. I happen to be on a windows machine without cygwin.

解决方案

Save this as findclass.sh (or whatever), put it on your path and make it executable:

#!/bin/sh
find "$1" -name "*.jar" -exec sh -c 'jar -tf {}|grep -H --label {} '$2'' \;

The first parameter is the directory to search recursively and the second parameter is a regular expression (typically just a simple class name) to search for.

$ findclass.sh . WSSubject

The script relies on the -t option to the jar command (which lists the contents) and greps each table of contents, labelling any matches with the path of the JAR file in which it was found.

这篇关于找到一个jar文件给出类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆