Logback配置问题,找不到logback.xml [英] Logback configuration issue, cannot find logback.xml

查看:587
本文介绍了Logback配置问题,找不到logback.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目配置为能够自动获取logback.xml(如果它与.jar文件位于同一目录中).通常,我只使用java -jar app.jar运行项目,logback会自动选择logback.xml并进行自我配置.

My project is configured to be able to pick up logback.xml automatically if it's located in the same directory as the .jar file. Normally I just run my project with java -jar app.jar and logback picks up logback.xml automatically and configures itself.

这些是我的MANIFEST.MF文件的内容:

These are the contents of my MANIFEST.MF file:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: Dev
Build-Jdk: 1.7.0_45
Main-Class: com.app.middleware.App
Class-Path: .

但是,一旦我添加了新的Maven依赖关系(ActiveMQ客户端5.9.1),Logback似乎就无法从类路径中提取配置文件-它仅打印以下内容:

However, once I added a new Maven dependency (ActiveMQ client 5.9.1), Logback seems to have become unable to pick up the configuration file from classpath - it simply prints the following:

20:17:58,872 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.xml]
20:17:58,872 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Setting up default configuration.

我将旧的jar和新的jar相互提取,并且两个档案的MANIFEST.MF和.classpath文件的内容完全相同.

I've extracted the old jar and the new jar alongside each other and both archives have the exact same contents of MANIFEST.MF and .classpath files.

这可能是由ActiveMQ引入的某种jar冲突引起的吗?为什么它会阻止logback获取其配置文件?

Could this be caused by some kind of jar conflict introduced by ActiveMQ? Why would it prevent logback from picking up its configuration file?

我目前正在通过手动指定配置位置(-Dlogback.configurationFile=logback.xml)来解决此问题,但我担心此问题是由更深层次的潜在问题导致的.

I am currently getting around this problem by manually specifying the config location (-Dlogback.configurationFile=logback.xml) but I fear that this problem is a result of a deeper underlying issue.

推荐答案

将logback.xml放入应用程序类路径的基本包中.

Put a logback.xml into the base package of your applications classpath.

这篇关于Logback配置问题,找不到logback.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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