Execute jar command exclude files

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):

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

This can be done with a command:

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

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 purpose find command is used with 2 conditions:

  1. -not -path "*/.svn*" filters out all svn files
  2. -not -type d filters out all directories

This will exclude empty directories from the jar though.

Tags:

Java

Jar