ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas L Roche <tlro...@us.ibm.com>
Subject Re: how to (usably) include one JAR in another?
Date Thu, 01 Dec 2005 17:56:07 GMT





Tom Roche 11/30/2005 10:35:26 PM:
>>>> How best to make the <jar> task include the JAR's classes, not
>>>> the JAR itself?

Jon Skeet Thu, 01 Dec 2005 08:50:03 GMT
>>> Have you tried using <zipfileset>?

Tom Roche 12/01/2005 10:57 AM
>> <target name="project.jar" depends="init, compile"
>>   description="Build project.jar">
>>   <jar
>>     jarfile="${build.result.folder}/project.jar">
>>     <fileset dir="${compile.outdir}">
>>         <include name="**/*.class"/>
>>     </fileset>
>>     <zipfileset dir="${lib.dir}">
>>         <include name="**/*.jar"/>
>>     </zipfileset>
>>     <manifest>
>>        <attribute name="Main-Class" value="foo.bar.project"/>
>>     </manifest>
>>   </jar>
>> </target>

>> $ zipinfo project/build/project.jar
>> Archive:  project/build/project.jar   194207   24
>> drwxr-xr-x  2.0 unx        0 bx stor  1-Dec-05 10:40 META-INF/
>> <snip>
>> -rw-r--r--  2.0 unx   180799 b- defN  7-May-05 21:42
commons-net-1.4.0.jar

>> What I want is to include its classes, not the JAR itself. Am I
>> misusing <zipfileset>?

Matt Benson Thu, 1 Dec 2005 08:29:59 -0800 (PST)
> Firstly, you're using zipfileset incorrectly.

I guessed :-(

> Next, If you don't know all the jars, you'll have to iterate. I
> would suggest you use ant-contrib <for>: for each file @{f} in
> <fileset dir="${lib.dir}" includes="**/*.jar" />, add <zipfileset
> src="@{f}" /> to ${build.result.folder}/project.jar with <jar
> update="true" /> (not tested).

In this case I know the JAR, so I set some properties and did

<target name="project.jar" depends="init, compile"
  description="Build project.jar">
  <jar update="true"
    jarfile="${output.jar}">
    <fileset dir="${compile.outdir}">
        <include name="**/*.class"/>
    </fileset>
    <zipfileset src="${input.jar}"/>
    <manifest>
      <attribute name="Main-Class" value="foo.bar.project"/>
    </manifest>
  </jar>
</target>

$ zipinfo project/build/project.jar
Archive:  project/build/project.jar   210424   166
drwxr-xr-x  2.0 unx        0 bx stor  1-Dec-05 12:47 META-INF/
<snip>
drwxr-xr-x  2.0 unx        0 b- stor  1-Dec-05 12:47 org/
drwxr-xr-x  2.0 unx        0 b- stor  1-Dec-05 12:47 org/apache/
drwxr-xr-x  2.0 unx        0 b- stor  1-Dec-05 12:47 org/apache/commons/
drwxr-xr-x  2.0 unx        0 b- stor  1-Dec-05 12:47
org/apache/commons/net/

and the classes follow. <woohoo/>

> This is an interesting use-case for which we can hopefully come up
> with a better solution using resource collections in Ant 1.7

But thanks for the one you gave!
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message