logback.xml和JetBrains IDEA IDE中运行的应用程序 [英] logback.xml and running application from JetBrains IDEA IDE

查看:308
本文介绍了logback.xml和JetBrains IDEA IDE中运行的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在IDEA中开发应用程序时,我应该在哪里放置logback.xml以对应用程序产生影响?

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

看来,当你运行/调试时,IDEA不会生成任何jar,也不会调用Maven来构建东西。它是否直接从编译的* .class文件中执行main()?如果是这样,我在哪里可以放置logback.xml以使其生效?

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?

推荐答案

logback。 xml 应该在CLASSPATH的根目录中可用。运行应用程序时,将在最开始打印完整的CLASSPATH。当我在 / src / main / resources (Maven项目)中放置 logback.xml 时,它没有任何问题。同时将它放在 / src / test / resources 中,并带有 logback-test.xml name已存在。

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.

只需运行:

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

看看它是否返回或 null

And see whether it returns something or null.

如果您不使用Maven项目,请打开项目结构 Ctrl + Alt + Shift + S )并添加 Modules 部分选择包含 logback.xml的文件夹并将其标记为来源(蓝色图标)。

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).

这篇关于logback.xml和JetBrains IDEA IDE中运行的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆