Reload Java class

I am using jboss server and have all my classes inside jar file.
Now, if I modify any of the java files, I need to replace the class file in the bank and restart the server.
Is there a way to dynamically load a newly created class file without restarting the server?

Thanks in advance.

+4
source share
3 answers

I had great success with JRebel (http://www.zeroturnaround.com/jrebel/). This is a very good product that makes it easy to reload the class for most of the changes you can make to the Java class. Restarting the application is not required, even if the application is required, the classes simply reload backstage.

It comes with a free 30-day trial so you can see if it works for you.

(Disclaimer: I am in no way affiliated with Zero Turnaround)

+1
source

It seems that you need to trick the server into restarting your application by changing web.xml - this means that you can open web.xml in the editor, enter a space, then delete and save the file or change the file modification date using the utility.

JBoss does not seem to have a convenient feature, such as the Tomcat reloadable = "true" flag in the Tomcat Server.xml file.

0
source

There are a number of solutions, none of which are particularly clean or easy.

As indicated, changing web.xml will reload the context and therefore update the source code, and this can be done without restarting the server. This works because "WEB-INF / web.xml" is configured as WatchedResource in the TOMCAT / conf / Context.xml file. That is, each context inherits this parameter and automatically looks at this file. You can remove this behavior, but you can also provide WatchedResource values ​​in your own web.xml to view additional files. Although I do not recommend it, you can add all your class files to this, and the context will reload when a single file changes.

A better solution depends on the class being reloaded when you drop the ClassLoader that loaded the class. Therefore, if you manage your hot-swappable code in your own ClassLoader, you can update your code without restarting the context if you update ClassLoader. Easier said than done, unfortunately, but you can start.

0
source

Source: https://habr.com/ru/post/1333003/


All Articles