Ant <jar> task: using excludes parameter

柔情痞子 提交于 2019-12-22 10:04:35

问题


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.


回答1:


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




回答2:


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.




回答3:


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

is equivalent to

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

i.e. it includes all files from the ${classes.src} directory and its subdirectories except those ending in .java (and except the default excludes)



来源:https://stackoverflow.com/questions/12707612/ant-jar-task-using-excludes-parameter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!