I have an application that has one executable JAR, which uses a library of other JARs. When I update a library JAR, the users close their program and open it again, and the new JARS are used. However, I have one JAR that contains only one class, that contains only fields. When this JAR is replaced on its own, the values in the fields from the old JAR appear to be used in the program.
The old JAR is gone from the file system at this point, so I'm a little confused as to where the values are coming from. My current solution is to update another JAR that is using the problematic JAR, but I'm not sure why this works so I'm looking for any insight that may be available.
Constants in java code can be inlined by the compiler. Example:
public class A {
public static final String STR = "foo";
}
public class B {
public static void main(final String... args) {
System.out.println(A.STR);
}
}
If you change STR to "bar" and recompile A, B will still print "foo" when running. The solution is to also recompile and update the code that uses the constants.
Also see Are all compile-time constants inlined?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With