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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:11:05+00:00 2026-05-31T01:11:05+00:00

Is it possible to unload Java standard libraries – those defined in the java.*

  • 0

Is it possible to unload Java standard libraries – those defined in the java.* packages?

My application needs to run JUnit tests, each with its own ClassLoader, like so:

for(String testClass : testClasses) {
    CustomClassLoader cl = new CustomClassLoader(this.getClass().getClassLoader());
    Class<?> _class = cl.loadClass(testClass);
    JUnitCore junit = new JUnitCore();
    Result result = junit.run( _class );
    registerResult(result, cl);
}

The problem that I am having is that some classes are not unloaded – the java.* classes.

If I do not unload them, then what happens is if the testing classes store objects using static methods, like those provided by the java.security.Security class, then I get a ClassCastException.

Is there any way for me to force their unloading?

  • 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-31T01:11:07+00:00Added an answer on May 31, 2026 at 1:11 am

    It is not possible to force unloading of classes. As long as a class or an instance of the class is referenced it wont be collected by the gc. You will have to remove these global values manually before or after each test.

    For unit tests you can try to run every test in a fresh jvm. (this will avoid static class data but wont avoid other global remains like files).

    These links may help:

    Running each JUnit test in a separate JVM in Eclipse?

    How to tell Maven2 to execute jUnit tests one by one each in new JVM instance?

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

Sidebar

Related Questions

I've integrated JQuery File Upload into a Java Spring application. The returned JSON is
Is it possible to make a Workflow not unload when it has become idle?
I'm currently looking for good (and free if possible) Web RAD (Rapid Application Development)
I am trying to unload a dll in java. I have read this and
I have a java application that will take the image as an input and
I'm making an application where people can upload a java code and do stuff
Is it possible to have flash access a generic twain scanner from my web-application,
I'm designing a stand-alone, multi-threaded application in Java. I'm trying to choose the best
I created a small application that, when run, creates or updates some tables in
Recently, I upload the web application in my local to Google App Engine c:\LocalProject>c:\appengine-java-sdk-1.2.2\bin\appcfg.cmd

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.