Monday, January 9, 2017

Java : dynamically compile and load Java class

Idea:

1. Take java class source code
2. Compile it to a .class file
3. Load the class into main program using URI
4. Run the class

Tools needed (Java libraries):

JavaCompiler

java.net.URLClassLoader

Application:
Dynamic replacement of malfunction parts of remote application...


Detailed instructions  on Java class loading can be found in this forum thread:

Java compile and load class

If wewould like to replace existing class, that will probably require us to write a custom class loader. Because, all default class loaders in Java will skip loading the class if the class with same name is already loaded.

One idea:

Reserve a dynamic name for updated class ,and first look for it in your code....

No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...