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!

3
  • 1
    what's the usecase? You can hot deploy e.g. on OSGI without shutdown. Commented Mar 11, 2015 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. Commented Mar 11, 2015 at 14:56
  • You could try looking at this article: Class Loading and Reloading Commented Mar 23, 2015 at 11:06

1 Answer 1

-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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.