Is it possible that we keep our jar/war file running and one class file in the same directory which can be referred from jar/war? The requirement is I want to keep some common code in single file which can be referred by multiple running jars/wars and I don't have to re-deploy application if I can successfully just change the class file.
Asked
Active
Viewed 691 times
2
-
what would that file contain? java code? a compiled class? will it be a jar file? – sidgate Sep 14 '16 at 05:46
-
Don't go there. It will give you pain. If you still want to consider using EAR files or deploy them inside the server itself. – Thorbjørn Ravn Andersen Sep 14 '16 at 05:48
-
@sidgate it will be a complied class. – DontDiscloseMe Sep 14 '16 at 06:15
-
Why don't you build the common code into a separate jar file (like a shared common library) and use `ClassLoader` or other jar hotswapping techniques to load them during runtime. – Samuel Kok Sep 14 '16 at 06:46
-
@SamuelKok this is something I heard for the first time.I will do R&D for this.Thanx – DontDiscloseMe Sep 14 '16 at 07:15
-
Please, instead of tell him what not to do, try to tell him the answer to the question, whether is good practice or not, this is why SO is made for... – NaN Apr 24 '17 at 18:07
1 Answers
1
I would go for this question here: How should I load Jars dynamically at runtime?
And them try the answers from jodonnell, chris and allain-lalonde depending on how do you want to access these class files, if by URL or by file path, and if you want to use JAR files or CLASS files.
In any case you should try and see it for yourself if it fits your needs and is acceptable by your employer standards. At certain point, we need to think out of the box. Don't worry if one or other user dislikes this or that approach. This community if meant for ask and receive answers on how to do it, and not to not do it.