How to replace classes in a running application in java ?
up vote
18
down vote
favorite
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 method that asks for a letter from the user and generate a name in accordance. Now I want to change the logic in NameGeneration class and apply that particular change without stopping the application.
I did this to learn more about class loaders and can someone please explain the key concepts that I have to learn to do something like that or site any references ?
java classloader
add a comment |
up vote
18
down vote
favorite
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 method that asks for a letter from the user and generate a name in accordance. Now I want to change the logic in NameGeneration class and apply that particular change without stopping the application.
I did this to learn more about class loaders and can someone please explain the key concepts that I have to learn to do something like that or site any references ?
java classloader
add a comment |
up vote
18
down vote
favorite
up vote
18
down vote
favorite
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 method that asks for a letter from the user and generate a name in accordance. Now I want to change the logic in NameGeneration class and apply that particular change without stopping the application.
I did this to learn more about class loaders and can someone please explain the key concepts that I have to learn to do something like that or site any references ?
java classloader
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 method that asks for a letter from the user and generate a name in accordance. Now I want to change the logic in NameGeneration class and apply that particular change without stopping the application.
I did this to learn more about class loaders and can someone please explain the key concepts that I have to learn to do something like that or site any references ?
java classloader
java classloader
edited Jan 14 '13 at 10:53
Mohammad Faisal
3,394135398
3,394135398
asked Jan 14 '13 at 10:47
Prasad Weera
5253721
5253721
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
up vote
27
down vote
accepted
Here is a working test. Every 5 secs Test.main() reloads test.Test1.class from the file system and calls Test1.hello()
package test;
public class Test1
public void hello()
System.out.println("Hello !");
public class Test
static class TestClassLoader extends ClassLoader
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException
if (name.equals("test.Test1"))
try
InputStream is = Test.class.getClassLoader().getResourceAsStream("test/Test1.class");
byte buf = new byte[10000];
int len = is.read(buf);
return defineClass(name, buf, 0, len);
catch (IOException e)
throw new ClassNotFoundException("", e);
return getParent().loadClass(name);
public static void main(String args) throws Exception
for (;;)
Class cls = new TestClassLoader().loadClass("test.Test1");
Object obj = cls.newInstance();
cls.getMethod("hello").invoke(obj);
Thread.sleep(5000);
Run it. Then change and recompile Test1
System.out.println("Hello !!!");
while Test is running. You will see Test1.hello output changed
...
Hello !
Hello !
Hello !!!
Hello !!!
This is how eg Tomcat reloads webapps. It has a separate ClassLoader for each webapp and loads a new version in a new ClassLoader. The old one is GCed just like any Java object as well as the old classes.
Note that we loaded Test1 with TestClassLoader and invoked its first method with reflection. But all Test1 dependencies will be implicitly loaded with Test1 class loader, that is all the Test1 application will be loaded by JVM into TestClassLoader.
Thanks for the help. Having new class loader instance for every new class loading as you've done here solved the problem.
– Prasad Weera
Jan 14 '13 at 11:38
add a comment |
up vote
2
down vote
There are 2 ways:
- 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.
- 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
+1 for OSGi. It supports adding/ removing bundles at runtime out-of-the-box.
– Puce
Jan 14 '13 at 10:58
Thanks for the first suggestion. But I don't want to use OSGI as the only intention of this small application is learning core java class loading concepts.
– Prasad Weera
Jan 14 '13 at 11:05
add a comment |
up vote
1
down vote
It's really simple, you will use of advantage of a OOP and use interface, don't need to manage classloader
You can inject the implementation with a setter:
Create an interface called NameGeneration
Create n implementation NameGenerationImpl1, NameGenerationimpl2 for instance
In your client class define a variable:
NameGeneration nameGeneration ;
and the setter :
public void setNameGeneration(NameGeneration nameGeneration)
this.nameGeneration = nameGeneration ;
nameGeneration will generate what you want.
When you change the algorithm you change the implementation by doing for instance :
setNameGeneration(new NameGenerationImpl1()) ;
or
setNameGeneration(new NameGenerationImpl2()) ;
What isPOO? I don't get it.
– Mohammad Faisal
Jan 14 '13 at 11:06
@Mohammad: I think he means OOP...
– Uwe Plonus
Jan 14 '13 at 11:10
This is basically the strategy pattern.
– Uwe Plonus
Jan 14 '13 at 11:10
@Uwe Plonus you are right OOP and my example use strategy pattern coupled with dependancy injection.
– Jean-Christophe Blanchard
Jan 14 '13 at 11:15
add a comment |
up vote
0
down vote
What about a strategy pattern? It could be a better solution for your problem instead of using classloaders.
1
How it could help to him dynamically load changed version of classes?
– Andremoniy
Jan 14 '13 at 10:51
As I know startegy pattern would help to choose between several implementations as we prefer at run time by coding to an interface. But we cannot introduce a whole new implementation n the fly.
– Prasad Weera
Jan 14 '13 at 11:02
@Prasad you can inject on the fly : see my example above with strategy pattern and DI: setNameGeneration(Class.forName("com.bean.ClasseA").newInstance() )
– Jean-Christophe Blanchard
Jan 14 '13 at 11:17
add a comment |
up vote
0
down vote
You can write your own custom classloader. When ever there is change in the class file or resource/jar containing the class file (check the timestamp), destroy the previous classloader instance and create a new classloader instance which in turn will load the new class file.
add a comment |
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
27
down vote
accepted
Here is a working test. Every 5 secs Test.main() reloads test.Test1.class from the file system and calls Test1.hello()
package test;
public class Test1
public void hello()
System.out.println("Hello !");
public class Test
static class TestClassLoader extends ClassLoader
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException
if (name.equals("test.Test1"))
try
InputStream is = Test.class.getClassLoader().getResourceAsStream("test/Test1.class");
byte buf = new byte[10000];
int len = is.read(buf);
return defineClass(name, buf, 0, len);
catch (IOException e)
throw new ClassNotFoundException("", e);
return getParent().loadClass(name);
public static void main(String args) throws Exception
for (;;)
Class cls = new TestClassLoader().loadClass("test.Test1");
Object obj = cls.newInstance();
cls.getMethod("hello").invoke(obj);
Thread.sleep(5000);
Run it. Then change and recompile Test1
System.out.println("Hello !!!");
while Test is running. You will see Test1.hello output changed
...
Hello !
Hello !
Hello !!!
Hello !!!
This is how eg Tomcat reloads webapps. It has a separate ClassLoader for each webapp and loads a new version in a new ClassLoader. The old one is GCed just like any Java object as well as the old classes.
Note that we loaded Test1 with TestClassLoader and invoked its first method with reflection. But all Test1 dependencies will be implicitly loaded with Test1 class loader, that is all the Test1 application will be loaded by JVM into TestClassLoader.
Thanks for the help. Having new class loader instance for every new class loading as you've done here solved the problem.
– Prasad Weera
Jan 14 '13 at 11:38
add a comment |
up vote
27
down vote
accepted
Here is a working test. Every 5 secs Test.main() reloads test.Test1.class from the file system and calls Test1.hello()
package test;
public class Test1
public void hello()
System.out.println("Hello !");
public class Test
static class TestClassLoader extends ClassLoader
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException
if (name.equals("test.Test1"))
try
InputStream is = Test.class.getClassLoader().getResourceAsStream("test/Test1.class");
byte buf = new byte[10000];
int len = is.read(buf);
return defineClass(name, buf, 0, len);
catch (IOException e)
throw new ClassNotFoundException("", e);
return getParent().loadClass(name);
public static void main(String args) throws Exception
for (;;)
Class cls = new TestClassLoader().loadClass("test.Test1");
Object obj = cls.newInstance();
cls.getMethod("hello").invoke(obj);
Thread.sleep(5000);
Run it. Then change and recompile Test1
System.out.println("Hello !!!");
while Test is running. You will see Test1.hello output changed
...
Hello !
Hello !
Hello !!!
Hello !!!
This is how eg Tomcat reloads webapps. It has a separate ClassLoader for each webapp and loads a new version in a new ClassLoader. The old one is GCed just like any Java object as well as the old classes.
Note that we loaded Test1 with TestClassLoader and invoked its first method with reflection. But all Test1 dependencies will be implicitly loaded with Test1 class loader, that is all the Test1 application will be loaded by JVM into TestClassLoader.
Thanks for the help. Having new class loader instance for every new class loading as you've done here solved the problem.
– Prasad Weera
Jan 14 '13 at 11:38
add a comment |
up vote
27
down vote
accepted
up vote
27
down vote
accepted
Here is a working test. Every 5 secs Test.main() reloads test.Test1.class from the file system and calls Test1.hello()
package test;
public class Test1
public void hello()
System.out.println("Hello !");
public class Test
static class TestClassLoader extends ClassLoader
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException
if (name.equals("test.Test1"))
try
InputStream is = Test.class.getClassLoader().getResourceAsStream("test/Test1.class");
byte buf = new byte[10000];
int len = is.read(buf);
return defineClass(name, buf, 0, len);
catch (IOException e)
throw new ClassNotFoundException("", e);
return getParent().loadClass(name);
public static void main(String args) throws Exception
for (;;)
Class cls = new TestClassLoader().loadClass("test.Test1");
Object obj = cls.newInstance();
cls.getMethod("hello").invoke(obj);
Thread.sleep(5000);
Run it. Then change and recompile Test1
System.out.println("Hello !!!");
while Test is running. You will see Test1.hello output changed
...
Hello !
Hello !
Hello !!!
Hello !!!
This is how eg Tomcat reloads webapps. It has a separate ClassLoader for each webapp and loads a new version in a new ClassLoader. The old one is GCed just like any Java object as well as the old classes.
Note that we loaded Test1 with TestClassLoader and invoked its first method with reflection. But all Test1 dependencies will be implicitly loaded with Test1 class loader, that is all the Test1 application will be loaded by JVM into TestClassLoader.
Here is a working test. Every 5 secs Test.main() reloads test.Test1.class from the file system and calls Test1.hello()
package test;
public class Test1
public void hello()
System.out.println("Hello !");
public class Test
static class TestClassLoader extends ClassLoader
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException
if (name.equals("test.Test1"))
try
InputStream is = Test.class.getClassLoader().getResourceAsStream("test/Test1.class");
byte buf = new byte[10000];
int len = is.read(buf);
return defineClass(name, buf, 0, len);
catch (IOException e)
throw new ClassNotFoundException("", e);
return getParent().loadClass(name);
public static void main(String args) throws Exception
for (;;)
Class cls = new TestClassLoader().loadClass("test.Test1");
Object obj = cls.newInstance();
cls.getMethod("hello").invoke(obj);
Thread.sleep(5000);
Run it. Then change and recompile Test1
System.out.println("Hello !!!");
while Test is running. You will see Test1.hello output changed
...
Hello !
Hello !
Hello !!!
Hello !!!
This is how eg Tomcat reloads webapps. It has a separate ClassLoader for each webapp and loads a new version in a new ClassLoader. The old one is GCed just like any Java object as well as the old classes.
Note that we loaded Test1 with TestClassLoader and invoked its first method with reflection. But all Test1 dependencies will be implicitly loaded with Test1 class loader, that is all the Test1 application will be loaded by JVM into TestClassLoader.
edited Jan 14 '13 at 15:58
answered Jan 14 '13 at 11:21
Evgeniy Dorofeev
104k23140218
104k23140218
Thanks for the help. Having new class loader instance for every new class loading as you've done here solved the problem.
– Prasad Weera
Jan 14 '13 at 11:38
add a comment |
Thanks for the help. Having new class loader instance for every new class loading as you've done here solved the problem.
– Prasad Weera
Jan 14 '13 at 11:38
Thanks for the help. Having new class loader instance for every new class loading as you've done here solved the problem.
– Prasad Weera
Jan 14 '13 at 11:38
Thanks for the help. Having new class loader instance for every new class loading as you've done here solved the problem.
– Prasad Weera
Jan 14 '13 at 11:38
add a comment |
up vote
2
down vote
There are 2 ways:
- 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.
- 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
+1 for OSGi. It supports adding/ removing bundles at runtime out-of-the-box.
– Puce
Jan 14 '13 at 10:58
Thanks for the first suggestion. But I don't want to use OSGI as the only intention of this small application is learning core java class loading concepts.
– Prasad Weera
Jan 14 '13 at 11:05
add a comment |
up vote
2
down vote
There are 2 ways:
- 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.
- 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
+1 for OSGi. It supports adding/ removing bundles at runtime out-of-the-box.
– Puce
Jan 14 '13 at 10:58
Thanks for the first suggestion. But I don't want to use OSGI as the only intention of this small application is learning core java class loading concepts.
– Prasad Weera
Jan 14 '13 at 11:05
add a comment |
up vote
2
down vote
up vote
2
down vote
There are 2 ways:
- 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.
- 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
There are 2 ways:
- 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.
- 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
answered Jan 14 '13 at 10:55
Wins
1,68131744
1,68131744
+1 for OSGi. It supports adding/ removing bundles at runtime out-of-the-box.
– Puce
Jan 14 '13 at 10:58
Thanks for the first suggestion. But I don't want to use OSGI as the only intention of this small application is learning core java class loading concepts.
– Prasad Weera
Jan 14 '13 at 11:05
add a comment |
+1 for OSGi. It supports adding/ removing bundles at runtime out-of-the-box.
– Puce
Jan 14 '13 at 10:58
Thanks for the first suggestion. But I don't want to use OSGI as the only intention of this small application is learning core java class loading concepts.
– Prasad Weera
Jan 14 '13 at 11:05
+1 for OSGi. It supports adding/ removing bundles at runtime out-of-the-box.
– Puce
Jan 14 '13 at 10:58
+1 for OSGi. It supports adding/ removing bundles at runtime out-of-the-box.
– Puce
Jan 14 '13 at 10:58
Thanks for the first suggestion. But I don't want to use OSGI as the only intention of this small application is learning core java class loading concepts.
– Prasad Weera
Jan 14 '13 at 11:05
Thanks for the first suggestion. But I don't want to use OSGI as the only intention of this small application is learning core java class loading concepts.
– Prasad Weera
Jan 14 '13 at 11:05
add a comment |
up vote
1
down vote
It's really simple, you will use of advantage of a OOP and use interface, don't need to manage classloader
You can inject the implementation with a setter:
Create an interface called NameGeneration
Create n implementation NameGenerationImpl1, NameGenerationimpl2 for instance
In your client class define a variable:
NameGeneration nameGeneration ;
and the setter :
public void setNameGeneration(NameGeneration nameGeneration)
this.nameGeneration = nameGeneration ;
nameGeneration will generate what you want.
When you change the algorithm you change the implementation by doing for instance :
setNameGeneration(new NameGenerationImpl1()) ;
or
setNameGeneration(new NameGenerationImpl2()) ;
What isPOO? I don't get it.
– Mohammad Faisal
Jan 14 '13 at 11:06
@Mohammad: I think he means OOP...
– Uwe Plonus
Jan 14 '13 at 11:10
This is basically the strategy pattern.
– Uwe Plonus
Jan 14 '13 at 11:10
@Uwe Plonus you are right OOP and my example use strategy pattern coupled with dependancy injection.
– Jean-Christophe Blanchard
Jan 14 '13 at 11:15
add a comment |
up vote
1
down vote
It's really simple, you will use of advantage of a OOP and use interface, don't need to manage classloader
You can inject the implementation with a setter:
Create an interface called NameGeneration
Create n implementation NameGenerationImpl1, NameGenerationimpl2 for instance
In your client class define a variable:
NameGeneration nameGeneration ;
and the setter :
public void setNameGeneration(NameGeneration nameGeneration)
this.nameGeneration = nameGeneration ;
nameGeneration will generate what you want.
When you change the algorithm you change the implementation by doing for instance :
setNameGeneration(new NameGenerationImpl1()) ;
or
setNameGeneration(new NameGenerationImpl2()) ;
What isPOO? I don't get it.
– Mohammad Faisal
Jan 14 '13 at 11:06
@Mohammad: I think he means OOP...
– Uwe Plonus
Jan 14 '13 at 11:10
This is basically the strategy pattern.
– Uwe Plonus
Jan 14 '13 at 11:10
@Uwe Plonus you are right OOP and my example use strategy pattern coupled with dependancy injection.
– Jean-Christophe Blanchard
Jan 14 '13 at 11:15
add a comment |
up vote
1
down vote
up vote
1
down vote
It's really simple, you will use of advantage of a OOP and use interface, don't need to manage classloader
You can inject the implementation with a setter:
Create an interface called NameGeneration
Create n implementation NameGenerationImpl1, NameGenerationimpl2 for instance
In your client class define a variable:
NameGeneration nameGeneration ;
and the setter :
public void setNameGeneration(NameGeneration nameGeneration)
this.nameGeneration = nameGeneration ;
nameGeneration will generate what you want.
When you change the algorithm you change the implementation by doing for instance :
setNameGeneration(new NameGenerationImpl1()) ;
or
setNameGeneration(new NameGenerationImpl2()) ;
It's really simple, you will use of advantage of a OOP and use interface, don't need to manage classloader
You can inject the implementation with a setter:
Create an interface called NameGeneration
Create n implementation NameGenerationImpl1, NameGenerationimpl2 for instance
In your client class define a variable:
NameGeneration nameGeneration ;
and the setter :
public void setNameGeneration(NameGeneration nameGeneration)
this.nameGeneration = nameGeneration ;
nameGeneration will generate what you want.
When you change the algorithm you change the implementation by doing for instance :
setNameGeneration(new NameGenerationImpl1()) ;
or
setNameGeneration(new NameGenerationImpl2()) ;
edited Jan 14 '13 at 11:12
answered Jan 14 '13 at 10:56
Jean-Christophe Blanchard
39929
39929
What isPOO? I don't get it.
– Mohammad Faisal
Jan 14 '13 at 11:06
@Mohammad: I think he means OOP...
– Uwe Plonus
Jan 14 '13 at 11:10
This is basically the strategy pattern.
– Uwe Plonus
Jan 14 '13 at 11:10
@Uwe Plonus you are right OOP and my example use strategy pattern coupled with dependancy injection.
– Jean-Christophe Blanchard
Jan 14 '13 at 11:15
add a comment |
What isPOO? I don't get it.
– Mohammad Faisal
Jan 14 '13 at 11:06
@Mohammad: I think he means OOP...
– Uwe Plonus
Jan 14 '13 at 11:10
This is basically the strategy pattern.
– Uwe Plonus
Jan 14 '13 at 11:10
@Uwe Plonus you are right OOP and my example use strategy pattern coupled with dependancy injection.
– Jean-Christophe Blanchard
Jan 14 '13 at 11:15
What is
POO? I don't get it.– Mohammad Faisal
Jan 14 '13 at 11:06
What is
POO? I don't get it.– Mohammad Faisal
Jan 14 '13 at 11:06
@Mohammad: I think he means OOP...
– Uwe Plonus
Jan 14 '13 at 11:10
@Mohammad: I think he means OOP...
– Uwe Plonus
Jan 14 '13 at 11:10
This is basically the strategy pattern.
– Uwe Plonus
Jan 14 '13 at 11:10
This is basically the strategy pattern.
– Uwe Plonus
Jan 14 '13 at 11:10
@Uwe Plonus you are right OOP and my example use strategy pattern coupled with dependancy injection.
– Jean-Christophe Blanchard
Jan 14 '13 at 11:15
@Uwe Plonus you are right OOP and my example use strategy pattern coupled with dependancy injection.
– Jean-Christophe Blanchard
Jan 14 '13 at 11:15
add a comment |
up vote
0
down vote
What about a strategy pattern? It could be a better solution for your problem instead of using classloaders.
1
How it could help to him dynamically load changed version of classes?
– Andremoniy
Jan 14 '13 at 10:51
As I know startegy pattern would help to choose between several implementations as we prefer at run time by coding to an interface. But we cannot introduce a whole new implementation n the fly.
– Prasad Weera
Jan 14 '13 at 11:02
@Prasad you can inject on the fly : see my example above with strategy pattern and DI: setNameGeneration(Class.forName("com.bean.ClasseA").newInstance() )
– Jean-Christophe Blanchard
Jan 14 '13 at 11:17
add a comment |
up vote
0
down vote
What about a strategy pattern? It could be a better solution for your problem instead of using classloaders.
1
How it could help to him dynamically load changed version of classes?
– Andremoniy
Jan 14 '13 at 10:51
As I know startegy pattern would help to choose between several implementations as we prefer at run time by coding to an interface. But we cannot introduce a whole new implementation n the fly.
– Prasad Weera
Jan 14 '13 at 11:02
@Prasad you can inject on the fly : see my example above with strategy pattern and DI: setNameGeneration(Class.forName("com.bean.ClasseA").newInstance() )
– Jean-Christophe Blanchard
Jan 14 '13 at 11:17
add a comment |
up vote
0
down vote
up vote
0
down vote
What about a strategy pattern? It could be a better solution for your problem instead of using classloaders.
What about a strategy pattern? It could be a better solution for your problem instead of using classloaders.
answered Jan 14 '13 at 10:49
Uwe Plonus
8,01222640
8,01222640
1
How it could help to him dynamically load changed version of classes?
– Andremoniy
Jan 14 '13 at 10:51
As I know startegy pattern would help to choose between several implementations as we prefer at run time by coding to an interface. But we cannot introduce a whole new implementation n the fly.
– Prasad Weera
Jan 14 '13 at 11:02
@Prasad you can inject on the fly : see my example above with strategy pattern and DI: setNameGeneration(Class.forName("com.bean.ClasseA").newInstance() )
– Jean-Christophe Blanchard
Jan 14 '13 at 11:17
add a comment |
1
How it could help to him dynamically load changed version of classes?
– Andremoniy
Jan 14 '13 at 10:51
As I know startegy pattern would help to choose between several implementations as we prefer at run time by coding to an interface. But we cannot introduce a whole new implementation n the fly.
– Prasad Weera
Jan 14 '13 at 11:02
@Prasad you can inject on the fly : see my example above with strategy pattern and DI: setNameGeneration(Class.forName("com.bean.ClasseA").newInstance() )
– Jean-Christophe Blanchard
Jan 14 '13 at 11:17
1
1
How it could help to him dynamically load changed version of classes?
– Andremoniy
Jan 14 '13 at 10:51
How it could help to him dynamically load changed version of classes?
– Andremoniy
Jan 14 '13 at 10:51
As I know startegy pattern would help to choose between several implementations as we prefer at run time by coding to an interface. But we cannot introduce a whole new implementation n the fly.
– Prasad Weera
Jan 14 '13 at 11:02
As I know startegy pattern would help to choose between several implementations as we prefer at run time by coding to an interface. But we cannot introduce a whole new implementation n the fly.
– Prasad Weera
Jan 14 '13 at 11:02
@Prasad you can inject on the fly : see my example above with strategy pattern and DI: setNameGeneration(Class.forName("com.bean.ClasseA").newInstance() )
– Jean-Christophe Blanchard
Jan 14 '13 at 11:17
@Prasad you can inject on the fly : see my example above with strategy pattern and DI: setNameGeneration(Class.forName("com.bean.ClasseA").newInstance() )
– Jean-Christophe Blanchard
Jan 14 '13 at 11:17
add a comment |
up vote
0
down vote
You can write your own custom classloader. When ever there is change in the class file or resource/jar containing the class file (check the timestamp), destroy the previous classloader instance and create a new classloader instance which in turn will load the new class file.
add a comment |
up vote
0
down vote
You can write your own custom classloader. When ever there is change in the class file or resource/jar containing the class file (check the timestamp), destroy the previous classloader instance and create a new classloader instance which in turn will load the new class file.
add a comment |
up vote
0
down vote
up vote
0
down vote
You can write your own custom classloader. When ever there is change in the class file or resource/jar containing the class file (check the timestamp), destroy the previous classloader instance and create a new classloader instance which in turn will load the new class file.
You can write your own custom classloader. When ever there is change in the class file or resource/jar containing the class file (check the timestamp), destroy the previous classloader instance and create a new classloader instance which in turn will load the new class file.
answered Jan 14 '13 at 14:39
Abhay Yadav
635
635
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14316996%2fhow-to-replace-classes-in-a-running-application-in-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown