列出多个jar文件的内容 [英] List contents of multiple jar files

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

问题描述

我在一堆罐子里面搜索.class文件。

I am searching for a .class file inside a bunch of jars.

jar tf abc.jar 

适用于一个文件。我试过了

works for one file. I tried

find -name "*.jar" | xargs jar tf

什么都不打印。我能想到的唯一解决方案是解压缩所有,然后搜索。有没有更好的办法?我在LUnix上。

prints nothing. The only solution I can think of, is unzip all, then search. Is there a better way? I'm on LUnix.

编辑
扫描多个jar时,打印jar文件名一起很有用班级。这种方法效果很好:

Edit: When scanning many jars, it is useful to print the jar file name along with the class. This method works well:

find . | grep jar$ | while read fname; do jar tf $fname | grep SchemaBuilder && echo $fname; done

产生的样本输出:

  1572 Wed Jul 25 10:20:18 EDT 2007 org/apache/ws/commons/schema/SchemaBuilder$1.class
  1718 Wed Jul 25 10:20:18 EDT 2007 org/apache/ws/commons/schema/SchemaBuilder$2.class
 42607 Wed Jul 25 10:20:18 EDT 2007 org/apache/ws/commons/schema/SchemaBuilder.class
./XmlSchema-1.3.2.jar
  1572 Wed Jul 25 10:20:18 EDT 2007 org/apache/ws/commons/schema/SchemaBuilder$1.class
  1718 Wed Jul 25 10:20:18 EDT 2007 org/apache/ws/commons/schema/SchemaBuilder$2.class
 42607 Wed Jul 25 10:20:18 EDT 2007 org/apache/ws/commons/schema/SchemaBuilder.class
./XmlSchema.jar


推荐答案

你需要传递 -n 1 xargs 强制它为每个文件名运行一个单独的 jar 命令从查找

You need to pass -n 1 to xargs to force it to run a separate jar command for each filename that it gets from find:

find -name "*.jar" | xargs -n 1 jar tf

否则 xargs 的命令行看起来像 jar tf file1.jar file2.jar ... ,它与预期的含义不同。

Otherwise xargs's command line looks like jar tf file1.jar file2.jar..., which has a different meaning to what is intended.

一个有用的调试技术是在 xargs 运行命令之前坚持 echo

A useful debugging technique is to stick echo before the command to be run by xargs:

find -name "*.jar" | xargs echo jar tf

这将打印出完整的 jar 命令而不是执行它,这样你就可以看出它有什么问题。

This would print out the full jar command instead of executing it, so that you can see what's wrong with it.

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

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