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

  • Home
  • SEARCH
  • 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 7093403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:26:06+00:00 2026-05-28T08:26:06+00:00

Would it be possible to write Eclipse plugin, that: Whenever in our code we

  • 0

Would it be possible to write Eclipse plugin, that:

  1. Whenever in our code we use ClassA.staticMethod1(); (ClassA come from included external jar)

  2. Plugin creates ClassA in our project.

  3. It copies that one used method only (and all needed imports and dependent methods) from jar to newly created ClassA – Unneeded class methods aren’t copied to project and are still in external jar.

  4. When jar is removed all works fine.

What is your solution to achieve this?

thanks in advance

EDIT to clarify for @Thorbjørn Ravn Andersen:

given class is in a jar:

package com.ext.jar;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Utilities {

    public static Object giveFirstThing(){
        // some random method content to show what has to be removed and what has to stay
        List list = new ArrayList();    
        Object o = doThis();
        return null;        
    }   

    public static Object giveSecondThing(){
        List list = new LinkedList();       
        Object o = doThat();
        return null;        
    }       
    private static Object doThis(){
        Map<Integer, String> myMap = new HashMap<Integer, String>();
        return null;        
    }
    private static Object doThat(String ... param){
        Set set;
        return null;        
    }       
}

This class (in sources project), that uses only part (in this case 1 method, which uses other method) of that jar’s class:

package com.foo.bar;

import com.ext.jar.Utilities;

public class Runner {

    public static void main(String[] args) {

        Utilities.giveFirstThing();

    }
}

The result is: class from jar is recreated in my project, as a normal compilable class, without methods and Imports, that I didn’t need (so jar can be safety removed from project):

package com.ext.jar;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Utilities {

    public static Object giveFirstThing(){
        // some random method content to show what has to be removed and what has to stay
        List list = new ArrayList();    
        Object o = doThis();
        return null;        
    }   

    private static Object doThis(){
        Map<Integer, String> myMap = new HashMap<Integer, String>();
        return null;        
    }

}

SUM UP:

2 (of 4 total) method where needed, so they are copied.

4 (of 6 total) imports where needed, so they are copied too.

rest of class is ATM useless, so everything else is not copied.

EDIT2: I’ve added bounty, as a sign that I wish to find solution to this problem, which I believe could be useful open-source project. 🙂

  • 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-28T08:26:07+00:00Added an answer on May 28, 2026 at 8:26 am

    Although I am sure you probably could write an Eclipse plugin to do what you require, it sounds like a lot of work that you don’t need to do.

    I think the plugin you describe is essentially trying to achieve two things:

    1. Reduce the overall size of that library thus, reducing the overall size of your application.
    2. The ability to not require linking to a external library

    The idea of essentially reducing an external jar library to only the core functionality you require is basically one role that obfuscation is used for. Many open-source obfuscation tools are available for Java the most popular probably being Proguard. Proguard is highly configurable and useful tool that can be used to remove shrink code, optimize and then obfusticate it.

    The shrinking of current code from an obfuscation tool would fulfil the first goal that I think you are trying to achieve.

    On top of that obfuscation tools would achieve much better results than the techique described by the plugin. See some results of Proguard here.

    The second goal that you are trying to achieve seems a little odd. There is also nothing wrong with using external libraries. From a development point of view you want to know what your application dependencies are.

    Dependencies on libraries in large projects need to be assessed (for things like risk etc.) and ultimately need to be managed. The idea of editing the library by removing the parts that you don’t require might put you in danger of breaking licenses. It would also be an absolute nightmare if the original library is lost and all that existed was the created classes.

    It would be much easier to state what your application depends and use a library dependency tool. Apache Ivy is a tool which does this and ultimately helps others who you collaborate with, by showing what your application depends and giving them quick an easy ways to get those libraries.

    These types of tools tend to be used in larger projects where there are numerous dependencies and specific versions that must be used. For small projects you will mostly find they state that it requires only one or two libraries within the projects readme or build instructions.

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

Sidebar

Related Questions

Would it be possible to write a class that is virtually indistinguishable from an
Would it be possible to write a script that gave the user the ability
Not sure this is possible, but looking to write a script that would return
Is it possible to write a service program that would catch an event of
In vs2008, is it possible to write an extension methods which would apply to
What would be the absolute fastest possible way to write a string to the
A qustion about Eclipse PDE development: I write a small plugin for Eclipse and
I'm currently working on a plug-in for Eclipse that translates some custom Java code
Here's an interesting problem that I have just come across. It is possible to
I'm writing an Eclipse plugin for the JDT. I need a functionality that tracks

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.