alternate configuration files on the classpath

In the logback manual, http://logback.qos.ch/manual/configuration.html#configFileProperty, there is the following section
Specifying the location of the default configuration file as a system property
If you wish, you can specify the location of the default configuration file with a system property named logback.configurationFile. The value of this property can be a URL, a resource on the class path or a path to a file external to the application.
java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1
There is no example of using this property to refer to a configuration file on the classpath, for example, an alternate configuration file deployed in an application jar file. This is my requirement. I have two executables, the main one, and an auto-installer for it, code for which lives in the same jar file, with each executable launched by its own batch file. I tried placing an alternate config file on the root of the classpath inside the jar file (at the same directory as logback.xml). this does not seem to work. What is the correct format for defining -Dlogback.configurationFile= for a resource located in a jar file on the classpath or, for that matter, any other classpath resource more generically?

I have not used this system property. If your application does not include the installer code, but the installer includes the application code, then you can enclose "logback.xml" with the main application and "logback-test.xml" in the installer. Then "logback-test.xml" will be used if present, otherwise "logback.xml". Perhaps this is useful? -----Original Message----- From: logback-user-bounces@qos.ch [mailto:logback-user-bounces@qos.ch] On Behalf Of Steve Cohen Sent: 26. oktober 2012 21:49 To: 'logback users list' Subject: [logback-user] alternate configuration files on the classpath In the logback manual, http://logback.qos.ch/manual/configuration.html#configFileProperty, there is the following section
Specifying the location of the default configuration file as a system property
If you wish, you can specify the location of the default configuration file with a system property named logback.configurationFile. The value of this property can be a URL, a resource on the class path or a path to a file external to the application.
java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1
There is no example of using this property to refer to a configuration file on the classpath, for example, an alternate configuration file deployed in an application jar file. This is my requirement. I have two executables, the main one, and an auto-installer for it, code for which lives in the same jar file, with each executable launched by its own batch file. I tried placing an alternate config file on the root of the classpath inside the jar file (at the same directory as logback.xml). this does not seem to work. What is the correct format for defining -Dlogback.configurationFile= for a resource located in a jar file on the classpath or, for that matter, any other classpath resource more generically? _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

That won't really work since both programs use the same jar. I really need the ability to specify which jar-packaged config file to use from the command line. The documentation implies that this is possible, I just would like to know how. On 10/29/2012 06:43 AM, Thorbjørn Ravn Andersen wrote:
I have not used this system property.
If your application does not include the installer code, but the installer includes the application code, then you can enclose "logback.xml" with the main application and "logback-test.xml" in the installer.
Then "logback-test.xml" will be used if present, otherwise "logback.xml".
Perhaps this is useful?
-----Original Message----- From: logback-user-bounces@qos.ch [mailto:logback-user-bounces@qos.ch] On Behalf Of Steve Cohen Sent: 26. oktober 2012 21:49 To: 'logback users list' Subject: [logback-user] alternate configuration files on the classpath
In the logback manual, http://logback.qos.ch/manual/configuration.html#configFileProperty, there is the following section
Specifying the location of the default configuration file as a system property
If you wish, you can specify the location of the default configuration file with a system property named logback.configurationFile. The value of this property can be a URL, a resource on the class path or a path to a file external to the application.
java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1
There is no example of using this property to refer to a configuration file on the classpath, for example, an alternate configuration file deployed in an application jar file. This is my requirement. I have two executables, the main one, and an auto-installer for it, code for which lives in the same jar file, with each executable launched by its own batch file.
I tried placing an alternate config file on the root of the classpath inside the jar file (at the same directory as logback.xml). this does not seem to work.
What is the correct format for defining -Dlogback.configurationFile= for a resource located in a jar file on the classpath or, for that matter, any other classpath resource more generically? _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

Classpath paths look like "com/example/resource.xml" (no leading slash). This works for logback as well (tried it on my machine). Alternatively, you could use a JAR URL like "jar:file:/path/to/file.jar!/com/example/resource.xml". -Abraham

Thanks. This (the classpath without preceding slash - in my case, the name of the config file in the jar since it lived at the root of the jar) was what I assumed and it was not working. Will have to look deeper. On 10/29/2012 06:20 PM, Abraham Lin wrote:
Classpath paths look like "com/example/resource.xml" (no leading slash). This works for logback as well (tried it on my machine). Alternatively, you could use a JAR URL like "jar:file:/path/to/file.jar!/com/example/resource.xml".
-Abraham
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

Duh, never mind. There was an error in the configuration file. That, and not classpath issues, was the reason for the problem. Sorry for bothering the list over this triviality. On 10/31/2012 01:04 PM, Steve Cohen wrote:
Thanks.
This (the classpath without preceding slash - in my case, the name of the config file in the jar since it lived at the root of the jar) was what I assumed and it was not working. Will have to look deeper. On 10/29/2012 06:20 PM, Abraham Lin wrote:
Classpath paths look like "com/example/resource.xml" (no leading slash). This works for logback as well (tried it on my machine). Alternatively, you could use a JAR URL like "jar:file:/path/to/file.jar!/com/example/resource.xml".
-Abraham
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
participants (3)
-
Abraham Lin
-
Steve Cohen
-
Thorbjørn Ravn Andersen