Exclude Jar from Ant Build using zipgroupfileset

落花浮王杯 提交于 2020-01-01 18:44:04

问题


I have created a Jar Project which contains Filter. I need to use servlet-api.jar when I compile the Filter code.

But when I want to use the Jar in another application, I want to build the jar in such a way that it will exclude servlet-api.jar.

I am using Apache Ant with NetBeans 8:
I have added below code in build.xml.

<target name="-post-jar">
    <jar destfile="dist/MyJar.jar">
        <zipfileset src="dist/MyJarAsLibrary.jar"/>
        <zipgroupfileset dir="dist/lib/." excludes="javax/*"/>
    </jar>
</target>

I have used Apache Ant zipgroupfileset. But I searched on google I found the excludes for files. I tried with excluding the servlet packages as javax/*, but it did not work. No Idea how to exclude specific packages. I found few excludes with zipfileset, but I need to use zipgroupfileset and exclude the javax.servelt.* packages.


回答1:


The excludes attribute of zipgroupfileset is used to select the archives to pick entries from, not to filter the contents of the archives. zipgroupfileset always contains everything included inside the matched archives.

The simple solution if you know which archive contains the servlet classes is to exclude it from the zipgroupfileset and add an explicit zipfileset.

If you don't know the archive, you can mimic zipgroupfileset using the archives resource collection and wrap that into a restrict container. Something like

<restrict>
  <archives>
    <zips>
      <fileset dir="dist/lib/"/>
    </zips>
  </archives>
  <not>
    <name name="javax/servlet/*"/>
  </not>
</restrict>


来源:https://stackoverflow.com/questions/35577351/exclude-jar-from-ant-build-using-zipgroupfileset

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!