tags:

views:

579

answers:

3

I'm writing an Ant script to package a project into a WAR file. The software consists of several projects with their own source directories, libraries, etc.

The WAR task has a nested element lib which I'm currently working on. I currently have a reference of the required libs as a Path (containing several FileSets, which I use in a classpath reference. The lib, however, wants the input to be a FileSet, and it refuses a Path.

I tried converting my Path into a FileSet, but then I didn't get it to work as a classpath elsewhere.

Is there a way to convert a Path into a FileSet? I would hate to copy-paste the directories.

<path id="compile.libs">
 <fileset dir="${common.path}/lib" includes="*.jar"/>
 <fileset dir="${data.path}/lib" includes="*.jar"/>
 <fileset dir="${gui.path}/lib" includes="*.jar"/>
 <fileset dir="${gui.path}/WebContent/WEB-INF/lib" includes="*.jar"/>
</path>

...when used with <war ..><../> <lib refid="compile.libs"/> </war> leads to:

BUILD FAILED
build.xml:173: compile.libs doesn't denote a zipfileset or a fileset
+1  A: 

You may have several choices.

  1. You may provide more than one <lib> nested element to <war> task. Maybe this would be enough.
  2. You may preassemble all of your lib files in one temporary directory and then just reference that directory as a fileset.
  3. There is an ant-contrib PathToFileSet task, but it requires a central root directory, and this may not be a case with your compile.libs layout.

I think I would try option 1.

Alexander Pogrebnyak
Thanks for the tips. I wasn't aware of that ant-contrib task, and I think I'll give it a look anyways.
Henrik Paul
A: 

The jars in the classpath used to compile are not the same that needs to be packaged inside the war. For example: I'm sure you need servlet-api.jar to compile your project but you don't need it inside the war because the container provides it. And some jars aren't needed at compile time but at runtime.
I know I'm not answering your question, just want you to think what you are doing.

rodrigoap
While I'm aware of that problem, I appreciate the words of caution (for posterity). It would be great to be able to add exclusions to path refs. I would be ready to have fragments of paths, and then combining them into a larger one, if needed.
Henrik Paul
A: 

Hi Henrick, Can you explain me how did you solve issue ? cos i am facing same issue. My issue is path is specified in one build file and war task is in another build file.

So i want a way to specify a pattern set or something where i can specify different files, not from same root directory. (Like you have in path). Fileset needs one single root directory.

Jigar Shah