[英]JAR - extracting specific files
I have .class and .java files in JAR archive. 我在JAR存档中有.class和.java文件。 Is there any way to extract only .java files from it? 有没有办法从中提取.java文件? I've tried this command but it doesn't work: 我试过这个命令,但它不起作用:
jar xf jar-file.jar *.java
You can use the unzip
command which accepts wildcards in its arguments (which is not the case of the jar
command). 您可以使用unzip
命令在其参数中接受通配符(这不是jar
命令的情况)。 Something like this should do the trick ( disclaimer : not tested) 像这样的东西应该做的伎俩(免责声明:没有测试)
unzip youFile.jar "*.java"
To extract only certain files from a jar file, supply their filenames: 要仅从jar文件中提取某些文件,请提供其文件名:
C:\\Java> jar xf myFile.jar foo bar
Using wildcards is a shell thing, and you should not expect it to work when extracting from a JAR file (which, as you've realized, is the case). 使用通配符是一个shell的东西,你不应该期望它从JAR文件中提取时(正如你已经意识到的那样)。
What you can do, is supply a list of the files you want to extract, via the @
modifier: 你能做什么,是通过@
修饰符提供你想要提取的文件列表:
jar xf my.jar @myfiles.lst
where myfiles.lst
would be: myfiles.lst
将在哪里:
com/my/MyClass.java
com/my/MySecondClass.java
This file could easily be created automatically with creative use of jar tvf
, awk
and your desired extraction pattern. 通过创造性地使用jar tvf
, awk
和您想要的提取模式,可以轻松地自动创建此文件。 I'll leave that as an exercise and/or another SO question :-) 我将把它留作练习和/或另一个SO问题:-)
Or you could use unzip
- a JAR file is basically a zip-file. 或者你可以使用unzip
- 一个JAR文件基本上是一个zip文件。
Cheers, 干杯,
There shouldn't be any *.java files in a jar, only class files. jar中不应该有任何* .java文件,只有类文件。 You can check the content of the jar first by running: 您可以通过运行来检查jar的内容:
jar tvf jar-file.jar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.