• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JAR files cached in JVM ?

 
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a folder named lib which basically contains all the JAR files needed for the system.

Now, in some time, a specific JAR file will be automatically generated and replace an existing JAR file in the lib folder.

When doing so, the system is still seeing the old JAR file and not the new one.

Do i have to assume that the JAR file is cached in the JVMs cache ?

If yes, how can i resolve this issue ?

Thanks,
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JAR files are not cached, but the classes they contain are. Once a class is loaded, it's retained as long as the Classloader that loaded it exists. Therefore, If you want to load new versions of classes while your JVM is running, you simply have to unload the old ones first by discarding the Classloader that loaded them. To make this possible, you have to load the classes from a Classloader instance that you create yourself and can subsequently discard. Here's an article on loading classes with your own classloader.
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You for your reply, but please can you tell me how can i reload the .class files of the JAR ?

Thanks,
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You load classes out of a jar explicitly by using, for example, a java.net.UrlClassLoader. When you want to reload the classes, you make sure all the objects created using those classes are discarded, discard that UrlClassLoader, create a new one, and explcitly load the classes again.

Here's a trivial example which creates ten different versions of a class named "Test", loads each one in place of the last one, and creates an instance of each one (example from here):

 
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic