How to replace classes in a running application in java ?

后端 未结 6 2031
有刺的猬
有刺的猬 2020-12-04 18:36

Say I have a class named NameGenerator. I can use this to generate names according to a given logic. Then I write a TestNameGeneration class with a

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 18:45

    There are 2 ways:

    1. To overwrite the class loader you're using by first using the existing classloader to bootstrap your application and specifically for the class that you need to have dynamic update, you have to use the overwritten classloader.
    2. To use OSGi framework. Depending on the scale of your application, OSGi framework may not be a good choice as it requires you to follow it's coding convention.

    Hope it helps

提交回复
热议问题