Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant <jar> task: using excludes parameter

Tags:

java

build

ant

Got a following build.xml string:

<jar destfile="${lib.dir}/rpt.jar" basedir="${classes.src}" excludes="**/*.java" />

I am new to Ant and i don't understand how excludes string works. What files are affected? All java source files?

Thanks.

like image 909
johnny-b-goode Avatar asked Dec 12 '22 21:12

johnny-b-goode


2 Answers

First about the statement

<jar destfile="${lib.dir}/rpt.jar" basedir="${classes.src}" excludes="**/*.java" />

this target is used to package your files inside a jar archive

destfile : specifies the name and location of the destination file, the archive that would be created

basedir : specifies the base directory of the files that needed to be packaged. note that all files and subfolders would be included

excludes : this is used to exclude files from basedir that you dont need inside your package (jar)

Now to your question

what the above statement would do is that it will package all the files inside classes.src to $(lib.dir)/rpt.jar but will exclude any .java files found at or inside any sub folder of basedir.

EDIT : This exclude="*/.java" is generally done to exclude source code form the jar which would be used, distributed,exported etc

like image 94
Mukul Goel Avatar answered Dec 21 '22 09:12

Mukul Goel


Yes, with your code all Java files are excluded. Take a look at the pattern definition: This page explains pretty good, how the Ant patterns work. It also contains a lot of examples illustrating it. Patterns are used everywhere, so if you continue working with Ant, you really need to understand them.

The ** basically means every sub directory. And /*.java means every Java file in these directories.

like image 29
Peter Ilfrich Avatar answered Dec 21 '22 09:12

Peter Ilfrich