1

I'm making a program, that I basically never want to shut down, and hence, make the code automatically update. In the following link is described how to compile a java class : Compiling external .java files from within Java

What I really want to do, is also use these classes in the program compiling it. Compiling it once every let's say hour is easy with a thread, but in Eclipse it messes up if other classes which are already given and static, try to access a file that gets compiled real-time. Now a solution I could think of would be creating lots of empty functions so I could fill them in later.

Or - make any access to the class just reference the class and let the class be the only one accessing itself.

But is there an easier way to do this?

Thanks in advance!

Community
  • 1
  • 1
  • 1
    what's the usecase? You can hot deploy e.g. on OSGI without shutdown. – zeller Mar 11 '15 at 14:54
  • 1
    Is this a server? In this case an easier (or at least more usual) option is to spin up a new version, migrate traffic over and stop the old instance rather than trying to constantly hot-patch the running process. – Paolo Mar 11 '15 at 14:56
  • You could try looking at this article: Class Loading and Reloading – rghome Mar 23 '15 at 11:06

1 Answers1

-1

Doesn't seem to be so easy especially for any class in your application. However can be achieved for a select few which can be hidden behind a proxy and then loaded and reloaded post changes to the src in following 4 step approach that's similar to whats done for JSP:

  • Deploy selected source code and monitor file changes periodically
  • Compile Java code at runtime for the changed src files
  • Load/reload Java class at runtime using class loader
  • the up-to-date class to its caller

    Here is an article that explains it with src.

Kedar Parikh
  • 1,241
  • 11
  • 18