there is my solution to your problem:
config.properties
You define your configuration file trough parameter -DconfigurationFile
set to your JVM. Then try to find confiFile
in your classpath
(inside jar) if is not found then filesystem will be searched. Well, as last the properties will be override with JVM parameters.
Properties prop = new Properties();
String configFile = System.getProperty("configurationFile",defaultConfigurationFile);
try {
InputStream classPathIo = getClass().getClassLoader().getResourceAsStream(configFile);
if(classPathIo != null) {
prop.load(classPathIo);
} else {
prop.load(new FileReader(configFile));
} catch (FileNotFoundException e) {
log.warn("The config file {} cannot be found. It can be setup by -DconfigurationFile parameter.",configFile);
} catch (IOException e) {
log.warn("The config file {} is not readable.",configFile);
} finally {
log.info("Configuration loaded! {} values found from configFile {}.",prop.entrySet().size(),configFile);
prop.putAll(System.getProperties());
}
log4j.properties
The solution is using of the following JVM parameter:
-Dlog4j.configuration={path to file}
If the file is NOT in the classpath (in WEB-INF/classes in case of Tomcat) but somewhere on you disk, use file:, like
-Dlog4j.configuration=file:/somewhere/on/disk/log4j.properties
hibernate.cfg.xml
I have no idea how to do this. Anyway, it hard to configure persistance after release because the configuration is hard bind to implementation. I think it is OK to keep it inside classpath.