I have deployed a application on Tomcat 6 and after I deployed I wanted to do some changes on my constant class and I uploaded only the constant class (.class file) into exploded war file.
And even after I restart the server several times the changes I made wouldn’t show.
All I changed was some strings in constants. What would you suggest me to do other than uploading war file again?
You will have to recompile all classes that reference those
Stringconstants.Note that a
static finalfield of a primitive type or of typeStringthat is initialized with a compile time constant value (a so called constant variable) will be inlined when they are used in other classes.In other words if you have these classes:
Then at compile time the value of
FOOwill be compiled into the.classfile ofBar, meaning thatBarno longer referencesConstantsat runtime!This also means that any change of
FOOwill have no effect onBaruntil you re-compileBarwith the newConstants.class.This effect is discussed at length in JLS §13.4.9
finalFields and Constants.One way to avoid this problem in the future is to ensure that your “constants” are not interpreted as constant variables by the compiler. One way to do this is to move the assignment of a value from an initializer to a simple assignment via a static initializer block: