Difference between setting classpath in build.xml using file set and patches

I have a build file that declares a classpath as shown

<path id="compile.classpath"> <fileset dir="${basedir}/lib" includes="**"/> <fileset dir="${jboss.home}/lib" includes="**"/> <pathelement path ="${build.classes.dir}"/> </path> 

I tried to look at the documentation, but I cannot understand the use of pathelement .

I know that the identifier is used to refer to this class path when performing the task, and the set of files includes jarfiles.

edit 1: My doubt is why we cannot use fileset to include class files instead of pathelement ?

+4
source share
2 answers

Last Edit:

My doubt is why we cannot use a set of files to include class files instead of pathelement?

If you use a set of files, you must add the set of class files to the path as follows:

 CLASSPATH=classes/MyClass1.class:classes/MyClass2.class:classes/MyClass3.class:.... 

When Java expects to see simply:

 CLASSPATH=classes 

Only jar files (and WAR, EAR, etc.) are explicitly specified in the class path (Java will open them and load their class files), hence the need for a set of files in ANT.

Update

Here's the Oracle documentation:

Class paths to .jar, .zip, or .class files. Each class path must end with a file name or directory , depending on what you set the class path for:

  • For a .jar or .zip file that contains .class files, the class path ends with the name of the .zip or .jar file.
  • For .class files in an unnamed package, the class path ends with the directory that contains the .class files.
  • For .class files in a named package, the class path ends with a directory that contains the "root" package (the first package in the full name of the package).
+5
source

There was already a similar question about the 'pathelements' here . From the documentation provided: "If this is a path structure, as in your example:" A path-like structure may include a link to another structure similar to the path (the path that is the resource collection itself) through nested elements "

  <path id="base.path"> <pathelement path="${classpath}"/> <fileset dir="lib"> <include name="**/*.jar"/> </fileset> <pathelement location="classes"/> </path> 

If this is a classpath structure: "The path attribute is for use with predefined paths"

 <classpath> <pathelement path="${classpath}"/> <pathelement location="lib/helper.jar"/> </classpath> 
+2
source

All Articles