logback.xml and running application from JetBrains IDEA IDE

老子叫甜甜 提交于 2020-02-01 02:12:26

问题


When I develop application in IDEA, where should I place logback.xml for it to have an effect on the application?

It seems when you run/debug IDEA doesn't make any jars and doesn't invoke Maven to build something. Does it execute main() directly from compiled *.class file? If so, where can I put logback.xml so that it would have effect?


回答1:


logback.xml should be available in the root directory of your CLASSPATH. When you run your application, the full CLASSPATH is printed at the very beginning. When I put logback.xml in /src/main/resources (Maven project) it works without any problem. Also putting it in /src/test/resources with logback-test.xml name has presence.

Simply run:

getClass().getClassLoader().getResource("/logback.xml");

And see whether it returns something or null.

If you are not working with Maven project, open Project structure (Ctrl + Alt + Shift + S) and add in Modules section select folder containing logback.xml and mark it as Sources (blue icon).



来源:https://stackoverflow.com/questions/5612832/logback-xml-and-running-application-from-jetbrains-idea-ide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!