<div dir="ltr">Hi Tony,<div><br></div><div style>I believe I found the issue.</div><div style><br></div><div style>I have the jar and the properties file inside dir1. I am calling the jar from the parent directory of dir1 using the command below:</div>
<div style><br></div><div style>java -jar dir1/myapp.jar</div><div style><br></div><div style>I believe this caused logback to try to find the properties file on the current directory, which is the parent of dir1. Is there a way for logback to be able to constantly loading the properties from the same directory that the jar is in?</div>
<div style><br></div><div style>Thanks,</div><div style>Suriyanto</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Apr 20, 2013 at 9:25 AM, Tony Trinh <span dir="ltr"><<a href="mailto:tony19@gmail.com" target="_blank">tony19@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm not sure why that quick test (using the "file" attribute, and running the jar from the same directory as log.properties) did not work for you. It worked for me in OSX Mountain Lion and JDK 6. The PropertyAction [1] passes the "file" attribute's value directly to FileInputStream [2], which uses File [3]. The Oracle javadocs should provide more details.<div>
<br></div><div>It turns out the "resource" attribute should also work in this case (I've confirmed on my machine). This uses ClassLoader.getResource(), whose search order is defined by [4]. You need to include the directory of log.properties in the jar's classpath either by command-line or from the jar's manifest [5][6].</div>
<div><br></div><div>[1] <a href="https://github.com/qos-ch/logback/blob/master/logback-core/src/main/java/ch/qos/logback/core/joran/action/PropertyAction.java#L72" target="_blank">https://github.com/qos-ch/logback/blob/master/logback-core/src/main/java/ch/qos/logback/core/joran/action/PropertyAction.java#L72</a></div>
<div>[2] <a href="http://docs.oracle.com/javase/6/docs/api/java/io/FileInputStream.html" target="_blank">http://docs.oracle.com/javase/6/docs/api/java/io/FileInputStream.html</a></div><div>[3] <a href="http://docs.oracle.com/javase/6/docs/api/java/io/File.html" target="_blank">http://docs.oracle.com/javase/6/docs/api/java/io/File.html</a></div>
<div>[4] <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/ClassLoader.html#getResource%28java.lang.String%29" target="_blank">http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/ClassLoader.html#getResource%28java.lang.String%29</a></div>
<div>[5] <a href="http://stackoverflow.com/questions/9532716/adding-the-current-directory-to-a-jar-files-classpath" target="_blank">http://stackoverflow.com/questions/9532716/adding-the-current-directory-to-a-jar-files-classpath</a><br>
</div>
<div>[6] <a href="http://stackoverflow.com/questions/4126030/executable-jar-wont-find-the-properties-files" target="_blank">http://stackoverflow.com/questions/4126030/executable-jar-wont-find-the-properties-files</a><br>
</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra">
<br><br><div class="gmail_quote">On Sat, Apr 20, 2013 at 12:08 AM, Suriyanto <span dir="ltr"><<a href="mailto:suriyanto@gmail.com" target="_blank">suriyanto@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Thanks again, Tony.<div><br></div><div>Yes, if I use absolute path, it will work. However I want to use the relative path so the user can put the jar and properties file anywhere as long as they are put in the same directory.</div>
<div><br></div><div>I tried to cd to dir and run from there, but logback still tells me that it cannot find the properties file. Is there a way for me to know what the absolute mapping that logback use when I provide a relative path?</div>
<div><br></div><div>Thanks.</div></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Apr 19, 2013 at 9:15 PM, Tony Trinh <span dir="ltr"><<a href="mailto:tony19@gmail.com" target="_blank">tony19@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Ok. The file-lookup is relative to your current working directory (unless you use absolute paths). You can confirm by cd'ing into /dir and then invoking your jar.<div>
<br></div>
<div>An alternative is to use an absolute path to a designated "data" directory (with environment variables). For example:</div><div><br></div><div> <property file="${HOME}/.myapp/log.properties" /><br>
</div>
<div> <property file="${APPDATA}/.myapp/log.properties" /><br></div><div> <property file="${PROGRAMFILES}/MyApp/log.properties" /><br></div>
<div><br></div><div><br></div></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Apr 19, 2013 at 9:22 PM, Suriyanto <span dir="ltr"><<a href="mailto:suriyanto@gmail.com" target="_blank">suriyanto@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks for answering.<div><br></div><div>I actually wanted to put the file outside the jar so the user can easily modify it for any of their environment. The file will be on the same directory as the jar file.</div>
<div><br></div><div>/dir</div><div> myapp.jar</div><div> log.properties</div><span><font color="#888888"><div><br></div><div>Suriyanto</div></font></span></div><div><div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Fri, Apr 19, 2013 at 7:00 PM, Tony Trinh <span dir="ltr"><<a href="mailto:tony19@gmail.com" target="_blank">tony19@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">If the file is in your JAR, you should be using the "resource" attribute instead of "file" (which searches your host filesystem).<div>
<br></div><div><font face="courier new, monospace"> <property resource="log.properties" /></font></div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Fri, Apr 19, 2013 at 8:39 PM, Suriyanto <span dir="ltr"><<a href="mailto:suriyanto@gmail.com" target="_blank">suriyanto@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">Hello,<div><br></div><div>I am following the instruction in the Logback manual to use an external property file.</div>
<div><br></div><div><property file="log.properties" /><br>
</div><div><br></div><div>I have log.properties file in the same directory as my executable jar file, which are created as an uber jar file from Maven plugin.</div><div><br></div><div>However, I keep getting the error: ERROR in ch.qos.logback.core.joran.action.PropertyAction - Could not find properties file [log.properties].</div>
<div><br></div><div>Am I putting the file in the correct directory?</div><div><br></div><div>Thanks,</div><div>Suriyanto</div></div>
<br></div></div>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch" target="_blank">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></blockquote></div><br></div>
<br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch" target="_blank">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch" target="_blank">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch" target="_blank">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch" target="_blank">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></blockquote></div><br></div>