Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute jar command exclude files

Tags:

java

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?

like image 725
Dejell Avatar asked Jan 04 '11 07:01

Dejell


3 Answers

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.

like image 82
silnijlos Avatar answered Nov 02 '22 15:11

silnijlos


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
like image 3
Andreas Dolk Avatar answered Nov 02 '22 14:11

Andreas Dolk


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.

like image 1
vasan ramani Avatar answered Nov 02 '22 13:11

vasan ramani