A common approach is to use paths relative to a system property. This allows you to specify the root folder in the OS specific format (C:\...
or /opt/
) and attach the relative part later.
Note that Java can handle Windows and Unix relative paths, so new File( "C:\\app", "conf/log4j.xml" )
will actually try to open C:\app\conf\log4j.xml
.
In your case, you could use this code:
File confFolder = new File( System.getProperty( "confDir" ) );
File log4j = new File( confFolder, "log4j.xml" );
Another option is to replace variable names in config files. That way you can have
<logConfDir>${appRoot}/conf</logConfDir>
<log4j>${logConfDir}/log4j.xml</log4j>
If there is a System property logConfDir
, it should overwrite the config option. That will allow customers to do whatever they think necessary.