执行jar命令排除文件
我遵循了Java Archive Tool,但不能'找不到如何排除文件夹。
例如,我的工作副本目录下有文件:
workingcopy
--src
--.svn
-- com
--.svn
--WebContent
我只想从 src 下的类编译和创建 jar,不包括以 .svn 目录开头的所有文件夹。我想从 cmd
运行它,例如 jar -cf test.jar
等。
我该怎么做?
I followed The Java Archive Tool but couldn't find how to exclude folders.
For example, I have the files under working copy directory:
workingcopy
--src
--.svn
-- com
--.svn
--WebContent
I would like to compile and create jar only from the classes under src
excluding all folders starting with .svn directory. I want to run it from cmd
like jar -cf test.jar
etc..
How can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这可以通过命令来完成:
jar
的问题是,如果传递目录,它将递归地添加所有内容。因此,我们的目标是仅传递文件,并且仅传递路径中没有“.svn”子字符串的文件。为此,find
命令与 2 个条件一起使用:-not -path "*/.svn*"
过滤掉所有 svn 文件-not -type d< /code> 过滤掉所有目录
这将从 jar 中排除空目录。
This can be done with a command:
The problem with
jar
is that if directory is passed it will be added recursively with all content. So our goal is to pass only files and only those of them which doesn't have '.svn' substring in the path. For this purposefind
command is used with 2 conditions:-not -path "*/.svn*"
filters out all svn files-not -type d
filters out all directoriesThis will exclude empty directories from the jar though.
这可能是解决您的问题的实用方法:它不会排除 subversion 目录,而仅包含类文件(假设您不将类文件放在版本控制):
进一步增强:将代码与类文件分开。无论如何,您不想签入类文件(构建工件):
This could be a practical workaround for your problem: it will not exclude the subversion directory (directories) but include only class files (assuming, you don't put class files under version control):
Further enhancement: separate code from class files. You don't want to check in class files (build artefacts) anyway:
SVN中有一个概念叫Export。如果您使用它,您将获得没有 .svn 存储库的结构。与退房时略有不同。
此后,您必须能够从该目录而不是存储库文件夹执行常规 jar 命令。
There is a concept called Export in SVN. if you use that you will get the structure without the .svn repository. It is slightly different from the Check-Out.
After this you must be able to do a regular jar command from that directory instead of the repository folder.
正如 javamonkey79 所说,我不认为你可以做到这一点使用
jar
工具本身。您应该做的是考虑 ant 及其 jar 任务。As said by javamonkey79, I don' tthink you can do this just with the
jar
tool itself. What you should do is considering ant, and its jar task.通过诸如 maven 和 ant 和 gradle
This is easily achieved (along with many other things) by build tools like maven and ant and gradle
从 Java 11 开始,您可以使用感叹号 (!) 来排除文件或文件夹,并用竖线 (|) 分隔
示例:
在 Java 8 jar 上,使用来自 @silnijlos 的 find 查看很好的答案。
您还可以使用 maven、ant 或 gradle(如果有),maven 参考:
http://maven.apache.org/plugins/maven-war-plugin/examples/include -排除-war.html中的文件
From Java 11 you can use exlamation mark (!) to exclude files or folders, seperated by pipe (|)
Examples:
On Java 8 jar, see the great answer using find from @silnijlos
You can also use maven, ant or gradle if you have that available, reference for maven:
http://maven.apache.org/plugins/maven-war-plugin/examples/including-excluding-files-from-war.html
看起来 jar 程序本身无法做到这一点。您将需要添加一些其他类型的脚本来完成您正在寻找的内容。
看来您可能使用的是 Windows,所以我猜测您可以用这种方式写入缺失的部分。
希望这有帮助。
It doesn't look like the jar program by itself will be able to do this. You will need to add in some other type of script to accomplish what you are looking for.
It looks like you may be using windows, so my guess is that you could write in this missing pieces that way.
Hope this helps.