Find a jar file given the class name?(找到一个给定类名的jar文件?)
问题描述
这对于 Java 开发人员来说一定是一个非常基本的问题,但是在给定 类名 的情况下找到合适的 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?
例如,给定com.ibm.websphere.security.auth.WSSubject",你如何追踪合适的jar文件?(google"不是我要找的答案!)
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!)
java docs 没有给出 jar 文件的任何提示,显然 jar 文件的名称本身没有提供线索.
The java docs do not give any hint of the jar file, and obviously the names of the jar files themselves offer no clue.
Java 世界中一定有搜索本地 jars"或某种自动解析依赖项"的技巧.理想情况下,我正在寻找官方"的方式来做到这一点.我碰巧在没有cygwin的Windows机器上.
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.
推荐答案
将其保存为 findclass.sh(或其他),将其放在您的路径上并使其可执行:
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
该脚本依赖于 jar 命令(列出内容)的 -t 选项并 greps 每个目录,并用找到它的 JAR 文件的路径标记任何匹配项.
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文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:找到一个给定类名的jar文件?
基础教程推荐
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
