I need to set the codebase for the RMI application I'm working on at the moment and have done this successfully using first
try{
ResourceBundle config = ResourceBundle.getBundle("myApp");
String codeBaseUrl = config.getString("codeBaseUrl");
System.setProperty("java.rmi.server.codebase", codeBaseUrl);
} catch (Exception e) {
e.printStackTrace();
}
and later using
java -Djava.rmi.server.codebase=http://192.168.1.1/path/to/codebase ...
on the command line.
Both of these approaches allow for the codebase to be changed without the need to recompile, but the System.setProperty approach allows codebase to be bunlded into a properties file and the same launch command to be used.
Most of the tutorials/documentation I've read on this uses the -D approach leading me to believe this is accepted as best practice, but I've been unable to find anything that explains WHY I should use over the other.
Is -D considered best practice for setting system properties such as codebase, and what benefits does this give / what pitfalls does it avoid?