How to reference file one level above the web context

I am trying to use the <property file="logback.properties" /> tag in my logback.xml file to reference an external settings file. I want to use a relative path and specify the file one level above my application context. For example: <web server root>/apps/myapplication/web-inf/classes/logback.xml I want to put the logback.properties file at <web server root>/apps/. Do you know what relative path I need to use to do this? I've tried everything I can think of, including the following, but they did not work: <property file="../logback.properties" /> <property file="../../../logback.properties" /> <property file="/logback.properties" /> <property file="./logback.properties" /> Please help ... there has to be a way without using an absolute path! Dawson

Has anyone had to do this type of thing before? If I cannot use a relative path, are there recommendations for an alternative approach? On 05/11/2010 5:24 PM, Dawson Mossman wrote:
I am trying to use the <property file="logback.properties" /> tag in my logback.xml file to reference an external settings file. I want to use a relative path and specify the file one level above my application context. For example:
<web server root>/apps/myapplication/web-inf/classes/logback.xml
I want to put the logback.properties file at <web server root>/apps/. Do you know what relative path I need to use to do this?
I've tried everything I can think of, including the following, but they did not work: <property file="../logback.properties" /> <property file="../../../logback.properties" /> <property file="/logback.properties" /> <property file="./logback.properties" />
Please help ... there has to be a way without using an absolute path! Dawson

Hello Dawson, Contrary to spring for example, logback relative paths are relative to the current working directory and not relative to the referencing file. HTH, On 08/11/2010 3:37 PM, Dawson Mossman wrote:
Has anyone had to do this type of thing before? If I cannot use a relative path, are there recommendations for an alternative approach?
On 05/11/2010 5:24 PM, Dawson Mossman wrote:
I am trying to use the <property file="logback.properties" /> tag in my logback.xml file to reference an external settings file. I want to use a relative path and specify the file one level above my application context. For example:
<web server root>/apps/myapplication/web-inf/classes/logback.xml
I want to put the logback.properties file at <web server root>/apps/. Do you know what relative path I need to use to do this?
I've tried everything I can think of, including the following, but they did not work: <property file="../logback.properties" /> <property file="../../../logback.properties" /> <property file="/logback.properties" /> <property file="./logback.properties" />
Please help ... there has to be a way without using an absolute path! Dawson

Thanks, so in my example below ... what would I need to use for the relative path? On 08/11/2010 3:52 PM, Ceki Gülcü wrote:
Hello Dawson,
Contrary to spring for example, logback relative paths are relative to the current working directory and not relative to the referencing file.
HTH,
On 08/11/2010 3:37 PM, Dawson Mossman wrote:
Has anyone had to do this type of thing before? If I cannot use a relative path, are there recommendations for an alternative approach?
On 05/11/2010 5:24 PM, Dawson Mossman wrote:
I am trying to use the <property file="logback.properties" /> tag in my logback.xml file to reference an external settings file. I want to use a relative path and specify the file one level above my application context. For example:
<web server root>/apps/myapplication/web-inf/classes/logback.xml
I want to put the logback.properties file at <web server root>/apps/. Do you know what relative path I need to use to do this?
I've tried everything I can think of, including the following, but they did not work: <property file="../logback.properties" /> <property file="../../../logback.properties" /> <property file="/logback.properties" /> <property file="./logback.properties" />
Please help ... there has to be a way without using an absolute path! Dawson
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

On 08/11/2010 8:54 PM, Dawson Mossman wrote:
Thanks, so in my example below ... what would I need to use for the relative path?
Relative paths in logback follow the usual relative path conventions. For example, x.txt and ./x.txt designate the file x.txt located in the current working directory whereas .../x.txt designates the file x.txt located one directory above the current working directory, ../../x.txt designates -- well you get the idea.
On 08/11/2010 3:52 PM, Ceki Gülcü wrote:
Hello Dawson,
Contrary to spring for example, logback relative paths are relative to the current working directory and not relative to the referencing file.
HTH,
On 08/11/2010 3:37 PM, Dawson Mossman wrote:
Has anyone had to do this type of thing before? If I cannot use a relative path, are there recommendations for an alternative approach?
On 05/11/2010 5:24 PM, Dawson Mossman wrote:
I am trying to use the <property file="logback.properties" /> tag in my logback.xml file to reference an external settings file. I want to use a relative path and specify the file one level above my application context. For example:
<web server root>/apps/myapplication/web-inf/classes/logback.xml
I want to put the logback.properties file at <web server root>/apps/. Do you know what relative path I need to use to do this?
I've tried everything I can think of, including the following, but they did not work: <property file="../logback.properties" /> <property file="../../../logback.properties" /> <property file="/logback.properties" /> <property file="./logback.properties" />
Please help ... there has to be a way without using an absolute path! Dawson
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user
Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

There is no guarantee where the current working directory is set for a web application (which is what a relative path works from). You can, however, ask the JVM where it got the byte code from for a given class, by using http://www.exampledepot.com/egs/java.lang/ClassOrigin.html // Get the location of this class Class cls = this.getClass(); ProtectionDomain pDomain = cls.getProtectionDomain(); CodeSource cSource = pDomain.getCodeSource(); URL loc = cSource.getLocation(); // file:/c:/almanac14/examples/ (works for jar files too). You can then make the information available to logback and refer to ${myvariable}/logback.properties. /Thorbjørn -----Original Message----- From: logback-user-bounces@qos.ch [mailto:logback-user-bounces@qos.ch] On Behalf Of Dawson Mossman Sent: 8. november 2010 15:37 To: Logback-user@qos.ch Subject: Re: [logback-user] How to reference file one level above the web context Has anyone had to do this type of thing before? If I cannot use a relative path, are there recommendations for an alternative approach? On 05/11/2010 5:24 PM, Dawson Mossman wrote:
I am trying to use the <property file="logback.properties" /> tag in my logback.xml file to reference an external settings file. I want to use a relative path and specify the file one level above my application context. For example:
<web server root>/apps/myapplication/web-inf/classes/logback.xml
I want to put the logback.properties file at <web server root>/apps/. Do you know what relative path I need to use to do this?
I've tried everything I can think of, including the following, but they did not work: <property file="../logback.properties" /> <property file="../../../logback.properties" /> <property file="/logback.properties" /> <property file="./logback.properties" />
Please help ... there has to be a way without using an absolute path! Dawson
Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

Thanks for the advice. In the end, I loaded the logback config file myself programmatically which allowed me to store and retrieve it from where I wanted. LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); // the context was probably already configured by default configuration rules lc.reset(); configurator.doConfigure(realPath + "/" + this.getInitParameter("logback_filename")); } catch (JoranException je) { // StatusPrinter will handle this } On 09/11/2010 4:45 AM, Thorbjørn Ravn Andersen wrote:
There is no guarantee where the current working directory is set for a web application (which is what a relative path works from).
You can, however, ask the JVM where it got the byte code from for a given class, by using http://www.exampledepot.com/egs/java.lang/ClassOrigin.html
// Get the location of this class Class cls = this.getClass(); ProtectionDomain pDomain = cls.getProtectionDomain(); CodeSource cSource = pDomain.getCodeSource(); URL loc = cSource.getLocation(); // file:/c:/almanac14/examples/
(works for jar files too).
You can then make the information available to logback and refer to ${myvariable}/logback.properties.
/Thorbjørn
-----Original Message----- From: logback-user-bounces@qos.ch [mailto:logback-user-bounces@qos.ch] On Behalf Of Dawson Mossman Sent: 8. november 2010 15:37 To: Logback-user@qos.ch Subject: Re: [logback-user] How to reference file one level above the web context
Has anyone had to do this type of thing before? If I cannot use a relative path, are there recommendations for an alternative approach?
On 05/11/2010 5:24 PM, Dawson Mossman wrote:
I am trying to use the<property file="logback.properties" /> tag in my logback.xml file to reference an external settings file. I want to use a relative path and specify the file one level above my application context. For example:
<web server root>/apps/myapplication/web-inf/classes/logback.xml
I want to put the logback.properties file at<web server root>/apps/. Do you know what relative path I need to use to do this?
I've tried everything I can think of, including the following, but they did not work: <property file="../logback.properties" /> <property file="../../../logback.properties" /> <property file="/logback.properties" /> <property file="./logback.properties" />
Please help ... there has to be a way without using an absolute path! Dawson
Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user
participants (3)
-
Ceki Gülcü
-
Dawson Mossman
-
Thorbjørn Ravn Andersen