Exclude Jar from Ant Build using zipgroupfileset

Mandar Pandit

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.

Stefan Bodewig

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>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Extending Ant zipgroupfileset Type

From Dev

Exclude files in ant build

From Dev

Exclude files in ant build

From Dev

Ant Download a Jar at Build

From Dev

Unable to start main() from jar using ant

From Dev

In an Android Gradle build, how to exclude dependencies from an included jar file?

From Dev

Gradle build: Exclude resources files from Spring Boot Jar file

From Dev

Eclipse: How to build an executable jar using ant with external project dependencies?

From Dev

Exclude from build in CLion

From Dev

How to tell scons to exclude certain files from using the build cache

From Dev

maven: exclude jar from JDK

From Dev

Exclude resources from dependency jar

From Dev

Using Maven in Ant for jar dependencies

From Dev

java build ant file with external jar files

From Dev

How to build jar-file with ant?

From Dev

Exclude package from external JAR in Android Studio during Gradle build process

From Dev

How to exclude a jar-file from my Android library build target

From Dev

how to add source code to jar file using ant build.xml

From Dev

Exclude folders and files from build

From Dev

Maven - exclude folder from build

From Dev

Exclude folders and files from build

From Dev

Exclude .bak files from build

From Dev

Build JavaFX app using ant

From Dev

Ant/Build a JAR : Build failed, Reference task.path not found

From Dev

How to export only selected resources from OSB (Eclipse workspace) into sbconfig.jar using Ant?

From Dev

Gradle - Exclude file from being packaged with jar

From Dev

OpenEJB: How to exclude jar from module search?

From Dev

Gradle: How to exclude a particular package from a jar?

From Dev

Exclude .jar from compile in Android Studio with Gradle

Related Related

HotTag

Archive