开发者

Building a "fat jar" in ant using ivy without copying the jars to a lib directory

开发者 https://www.devze.com 2023-01-31 19:13 出处:网络
I\'m interesting in building a \"fat jar\" in my Java project where Ivy resolves the dependencies.It seems wasteful to me to have to copy the referenced jar files from the ivy cache to the local proje

I'm interesting in building a "fat jar" in my Java project where Ivy resolves the dependencies. It seems wasteful to me to have to copy the referenced jar files from the ivy cache to the local project, so I'd like to avoid doing that. I found a solution that works, but wonder if there is a slightly simpler way. In the code below what I thought would be easiest is for the zipfileset line to work, but it does not - the jars are included in the built jar file, but they are not expanded. If instead I use the section it works properly, but seems like a bit of extra fuss. Is there a cleaner way of doing this?

<target depends="clean, build" name="jar">
    <ivy:cachefileset setid="Ping.runclasspath" conf="default" />
    <jar destfile="dist/Ping.jar" filesetmanifest="merg开发者_如何学Goewithoutmain">
        <manifest>
            <attribute name="Main-Class" value="${main-class}"/>
            <attribute name="Class-Path" value="."/>
        </manifest>
        <fileset dir="build"/>
        <zipfileset refid="Ping.runclasspath"/>      <--- this does NOT work
        <restrict>                                   <--- this DOES work
           <name name="**/*.class"/>
           <archives>
              <zips>
                 <fileset refid="Ping.runclasspath"/>
              </zips>
           </archives>
        </restrict>
    </jar>
</target>


Have you experimented with zipgroupfileset? I don't know if it would actually work in your example, but it seems to have a similar purpose for existence.


I just had to do the same thing in one of my ant projects. Chris' suggestion of using zipgroupfileset works:

<target depends="clean, build" name="jar">
    <ivy:cachefileset setid="Ping.runclasspath" conf="default" />
    <jar destfile="dist/Ping.jar" filesetmanifest="mergewithoutmain">
        <manifest>
            <attribute name="Main-Class" value="${main-class}"/>
            <attribute name="Class-Path" value="."/>
        </manifest>
        <fileset dir="build"/>
        <zipgroupfileset refid="Ping.runclasspath"/>
    </jar>
</target>
0

精彩评论

暂无评论...
验证码 换一张
取 消