java 执行jar命令排除文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4591552/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 07:06:48  来源:igfitidea点击:

Execute jar command exclude files

javajar

提问by Dejell

I followed The Java Archive Toolbut couldn't find how to exclude folders.

我遵循了The Java Archive Tool,但找不到如何排除文件夹。

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 srcexcluding all folders starting with .svn directory. I want to run it from cmdlike jar -cf test.jaretc..

我想仅从src排除以 .svn 目录开头的所有文件夹下的类编译和创建 jar 。我想从cmdlikejar -cf test.jar等运行它。

How can I do it?

我该怎么做?

采纳答案by Andreas Dolk

This could be a practical workaround for your problem: it will not excludethe subversion directory (directories) but include only class files (assuming, you don'tput class files under version control):

这可能是您问题的实用解决方法:它不会排除subversion 目录(目录),而仅包含类文件(假设您没有将类文件置于版本控制之下):

jar -cf test.jar *.class

Further enhancement: separate code from class files. You don't want to check in class files (build artefacts) anyway:

进一步增强:将代码与类文件分开。无论如何,您不想签入类文件(构建人工制品):

workingcopy
--src
  --.svn
  -- com  // only *.java files in here and below
--.svn
--WebContent
--bin
  --com   // only *.class files in here and below

回答by silnijlos

This can be done with a command:

这可以通过以下命令完成:

jar cf test.jar `find . -not -path "*/.svn/*" -not -type d`

The problem with jaris that if directory is passed it will be added recursively with allcontent. So our goal is to pass only files and only those of them which doesn't have '.svn' substring in the path. For this purpose findcommand is used with 2 conditions:

问题jar在于,如果通过目录,它将与所有内容一起递归添加。所以我们的目标是只传递文件,并且只传递那些在路径中没有 '.svn' 子字符串的文件。为此,find命令与 2 个条件一起使用:

  1. -not -path "*/.svn*"filters out all svn files
  2. -not -type dfilters out all directories
  1. -not -path "*/.svn*"过滤掉所有 svn 文件
  2. -not -type d过滤掉所有目录

This will exclude empty directories from the jar though.

不过,这将从 jar 中排除空目录。

回答by Raghuram

This is easily achieved (along with many other things) by build tools like mavenand antand gradle

这可以通过构建工具(如mavenantgradle)轻松实现(以及许多其他事情)

回答by vasan ramani

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.

SVN中有一个叫做Export的概念。如果您使用它,您将获得没有 .svn 存储库的结构。它与退房略有不同。

After this you must be able to do a regular jar command from that directory instead of the repository folder.

在此之后,您必须能够从该目录而不是存储库文件夹执行常规 jar 命令。

回答by Valentin Rocher

As said by javamonkey79, I don' tthink you can do this just with the jartool itself. What you should do is considering ant, and its jar task.

正如javamonkey79 所说,我认为您不能仅使用jar工具本身来做到这一点。您应该做的是考虑ant及其jar 任务

回答by javamonkey79

It doesn't look like the jar program by itselfwill be able to do this. You will need to add in some other type of script to accomplish what you are looking for.

jar 程序本身似乎无法做到这一点。您将需要添加一些其他类型的脚本来完成您要查找的内容。

It looks like you may be using windows, so my guess is that you could write in this missing pieces that way.

看起来您可能正在使用 Windows,所以我的猜测是您可以通过这种方式编写缺少的部分。

Hope this helps.

希望这可以帮助。