Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7569663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:13:21+00:00 2026-05-30T15:13:21+00:00

I would like to know if it is possible to write an Ant task

  • 0

I would like to know if it is possible to write an Ant task (using some other library if necessary) to reduce a JAR file so that it contains only certain classes and those on which they depend.

For example, I have a JAR containing classes A, B, C and D, where A and B both extend C. D is independent of the others. What I would like to do is specify to an Ant task that I only need class B, and end up with a JAR file that contains only B and C.

I have seen this answer which provides a simple way to say “I don’t want A and D”, and I imagine that replacing “excludes” with “includes” would allow me to specify “I do want B and C” like this:

<jar destfile="stripped.jar">
    <zipfileset src="full.jar" includes="path/B.class;path/C.class"/>
</jar>

…but is there a dependency-aware way of doing this so that I can say “I want B” but end up with a JAR that contains B and its dependencies?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:13:22+00:00Added an answer on May 30, 2026 at 3:13 pm

    You could take a look at obfuscating tools, they can also often remove dead code, that is classes, methods and the like that are not referenced from anywhere in the code.

    For example, you could use ProGuard.

    From the documentation:

    ProGuard is a free Java class file shrinker, optimizer, obfuscater, and preverifier. It detects and removes unused classes, fields, methods, and attributes. It optimizes bytecode and removes unused instructions. It renames the remaining classes, fields, and methods using short meaningless names. Finally, it preverifies the processed code for Java 6 or for Java Micro Edition.

    You can configure it to do just the shrinker step. In your case, you would use the -keep option to tell ProGuard that you want the B class, and end up with B and C as you describe. This might not be exactly what you want however since ProGuard will also remove unused methods and the like, modifying the classes in your JAR file (I do not know of any option to turn this off). Also, you need to tell ProGuard not to do any of the other stuff it normally does, such as obfuscation.

    If ProGuard does not fit your needs, you can look for other obfuscation and/or shrinking tools. Hope this helps, and good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know if it is possible to write some software that
I would like to know how is possible to read a file placed in
I would like to know whether it is possible to write code that would
I would like to know if it's possible to write a migration instead of
I would like to know if it's possible to write a context menu extension
I would like to know if it is possible to write in a text
I would like to know IF and HOW it is possible to write a
I would like to know if it's possible to read a .mdb file without
I would like to know if it's possible to write a console application to
Hi I would like to know if its possible to do something similar to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.