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 7600023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:48:32+00:00 2026-05-30T22:48:32+00:00

I know already how to get all the packages available, however I’m trying to

  • 0

I know already how to get all the packages available, however I’m trying to only get the packages that I made in my own java project.

for example I don’t want java.util to show up in the list of packages.

I’m using this code to gather the classes:

List<String> result = new LinkedList<String>();

Package[] packages = Package.getPackages();

for(Package pack : packages)
{
    result.add(pack.getName());
}

And it works very good, now I just want to get rid of all the system packages.

Is there any way to filter the packages so that only the ones I’ve defined remain?

PS, I’m not worried about efficiency, the purpose of this can be as slow as it needs to be, it will only run once at the beginning of my program.

I have looked at several related questions, but none of them are what I am looking for.

If there is a way to tell if a package name is a system package, that will do the job perfectly.

EDIT!

I am making this as part of an API, and because of that I can’t really just compare the package name against a set token to see if it’s a package name I’m using, I don’t want there to be any editing required, just place the class file in my project and use it, regardless of what package names I choose.

One method I would try, howver it doesn’t seem to work, and gives me random errors, is scanning the jar file to check if there is a directory equivelant to the package name. Whenever I scan the jar file however I get the error “Can not access jar file, is it being used by another process?”.

Scanning the jar file would definitly work to see if the class existed in my project (jar file) but another limitation is that I have to compile to test it, can’t just test it in Eclipse, I edited the code 10 times trying to get the jar file search to work, and each time get access errors because javaw.exe is using the jar file it’s not allowing me to read the files inside of it.

Edit2!

Someone suggested that I make a list of all the known system classes and compare it to that list, which would work if different JDKs didn’t have some different classes, so I was wondering a new question sort of, is there any way to get all the jar files that are part of the current JRE System Library? Then I could read through those and add all their packages to the filters.

  • 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-30T22:48:33+00:00Added an answer on May 30, 2026 at 10:48 pm

    I don’t know about any method from this… just for classes.
    But you could make a own list by letting this run, maybe saving to a file for every operating system in an own program.

    Package[] pa = Package.getPackages();
    for (int i = 0; i < pa.length; i++) {
        Package p = pa[i];
        System.out.print("\"" + p.getName() + "\", ");
    }
    

    Then load this list and iterate through every package in your other program where you want to filter the packages…

    String[] systemPackages = new String[]{<all names of the packages>};
    Package[] pa = Package.getPackages();
    int n = 0;
    
    for (int i = 0; i < pa.length; i++) {
        Package p = pa[i];
        boolean isSystemPackage = false;
        String pname = p.getName();
        for (int j = 0; j < systemPackages.length; j++) {
            String spname = systemPackages[j];
            if (pname.equals(spname)) {
                isSystemPackage = true;
                systemPackages[j] = null;
                break;
            }
        }
        if (!isSystemPackage) {
            n++;
        } else {
            pa[i] = null;
        }
    }
    
    Package[] projectPackages = new Package[n];
    for (int i = 0, j = 0; i < pa.length; i++) {
        Package p = pa[i];
        if (p != null) {
            projectPackages[j] = p;
            j++;
        }
    }
    

    So you could kind of check it… sure there are different versions of the java-libraries but i dont think you want to use it that serious hm?

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

Sidebar

Related Questions

I'm sure that someone already posted this question; however, I would like to get
I know a similar question has already been asked, but that retrieves all the
I know how to get all files that match the search pattern in a
I know PHP 5 already supports SQLite but for some reason I can't get
I already know quite a few tricks with Android java and I have an
I already know that most implementations use a single thread, but is there anything
I guess you already know the question ;) Does the performance wizard only exist
I am trying to get all Inbox Messages using ContentResolver based on message ids
Hi I know that there are many questions already in SO related to my
OK, I know already all the reasons on paper why I should not use

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.