如何提取 java 中声明的字符串并将其放入 jar 文件中
是否有与 jar 文件的 Unix strings
命令等效的命令?
举个例子,如果我有这个 Java 文件:
public class Foo {
String foo = "I\'m so meta even this acronym";
}
编译并放置在 bar.jar 中
,理想情况下,我会喜欢在 bar.jar 上运行一些命令,该命令会将字符串“I'm so meta”发送到标准输出,这样我可以 grep 查找它。
我试图解决的问题是,我在 Java 程序中收到一条错误消息,我想知道它来自哪个 jar 文件。
Is there a equivalent to the Unix strings
command for jar files?
To give an example, if I have this Java file:
public class Foo {
String foo = "I\'m so meta even this acronym";
}
compiled and placed in bar.jar
I will, ideally, like to run some command on bar.jar which will send the string "I'm so meta" to standard output so I can grep for it.
The problem I am trying to solve is, I'm getting an error message in my Java program, and I will like to know which jar file its coming from.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这应该适合你:
unzip -p your.jar |strings| grep 'your string'
要搜索目录中的多个 JAR 文件,请使用:
unzip -p \*.jar |strings| grep '你的字符串'
This should work for you:
unzip -p your.jar |strings| grep 'your string'
To search through multiple JAR files in the directory use:
unzip -p \*.jar |strings| grep 'your string'
jar 只是 zip 文件,因此这是一个很好的起点。
似乎可行,但是解压缩可能会打印控制字符,因此可能会弄乱您当前的控制台。您最好将文件实际解压缩到一个目录中并在其上运行字符串。也许类似这样的事情会起作用,
我敢打赌有一种更有效的方法可以做到这一点,我确信一些 shell 脚本专家会为我清理这个问题。
Jars are just zip files so that is a good starting point.
seems to work, however unzip may print control characters so it could mess up your current console. You would be better to actually unzip the files into a directory and run strings on it. Probably something like this would work
I bet there is a more efficient way of doing that, some shell script guru will clean this up for me I'm sure.
如果您的错误消息引发异常,我建议您检查堆栈跟踪并获取引发异常的类和方法。然后使用 jad(java 反编译器)反编译该类并查看消息从哪里到达。
If your error message is thrown exception I'd suggest you to examine the stacktrace and get the class and method that throws exception. Then decompile the class using jad (java decompiler) and see where the message arrives from.
你可以在 Unix 中尝试“nohup”命令。这里所有异常和标准输出都将附加到一个文件中。
命令
现在查看文件 bar.out 以获取 jar 执行中的错误消息。
you can try a "nohup" command in Unix. here all exceptions and standard output will be append into a file
The command is
now see the file bar.out for the error messages in your jar execution.