10

I have been googling for the "Differences between fileset and path" article for some time, but have found nothing useful. For example, what is the difference between the following (say, there is a someDir directory, which contains .jar files and has no subdirectories):

<path id="somePathId">
    <pathelement path="someDir"/>
</path>

<path id="someId">
  <path refid="somePathId" />
</path>

and

<path id="someId">
  <fileset dir="someDir">
     <include name="*.*">
  </fileset>
</path>

?

martin clayton
  • 76,436
  • 32
  • 213
  • 198
Dmitry
  • 3,028
  • 6
  • 44
  • 66
  • By the way, there is a posibility to specify the one-file-fileset. Isn't it better to use a nested instead? – Dmitry Jul 01 '11 at 06:58

2 Answers2

2

The major difference between a <path> and a <fileset> is that in <fileset> you can specify if you want to include or exclude certain type of files (Basically, its a group of files within a path... not necessary all the files), for eg:

<path id="someId">
  <fileset dir="someDir">
     <include name="*.java">
     <include name="*.properties">
  </fileset>
</path>
Arpit
  • 6,212
  • 8
  • 38
  • 69
  • AFAIK this example won't work because it will search for files matching both expressions, i.e. `*.java` and `*.properties`. – Thresh Jul 01 '11 at 09:33
  • 2
    Yes, that's what I was trying to say .. I am searching for both of these files. If you cant to exclude a pattern, you can use ` – Arpit Jul 01 '11 at 10:00
  • 2
    @Arpit I mean that the script you specified will not work. `include` patterns are applied using `and` and there is no file that can match **both**. [Documentation](http://ant.apache.org/manual/Types/fileset.html): If any of the selectors within the FileSet do not select the file, the file is not considered part of the FileSet. This makes a FileSet equivalent to an selector container. – Thresh Jul 01 '11 at 10:04
2

They are used in different situations.

fileset is used to specify a group of files. You can use selectors and patternsets to get only the files you want.

classpath is used to specify classpath references. classpath can be specified with a single jar (location="..."), a ; or : separated list of jars (path="...") or with nested resource collections (like fileset).

Also if you want to debug them, it is different:

<echo message="Build-path: ${toString:build-path}" />

vs

<property name="debug.classpath" refid="classpath"/>
<echo message="Classpath = ${debug.classpath}"/>

As for your scripts,

<path id="somePathId">
    <pathelement location="someDir"/>
</path>

I did not test it but according to the documentation path= expects a ; or : separated list of jars. This is not the same as your second example.

cmcginty
  • 113,384
  • 42
  • 163
  • 163
Thresh
  • 943
  • 14
  • 23