Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse can't find logback-test.xml on my classpath for unit tests

I'm struggling with getting Eclipse to recognize my logging configuration when I quick run tests from within Eclipse (Alt + Shift + X, T), or by running from the Run Configurations. I really don't care all that much about logging from the tests per se, but really just providing the configuration so that any log statements executed will not fail.

Failed to instantiate [ch.qos.logback.classic.LoggerContext]
Reported exception:
java.lang.NoSuchMethodError: ch.qos.logback.core.util.Loader.getResourceOccurrenceCount(Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/util/Set;
	at ch.qos.logback.classic.util.ContextInitializer.multiplicityWarning(ContextInitializer.java:160)
	at ch.qos.logback.classic.util.ContextInitializer.statusOnResourceSearch(ContextInitializer.java:183)
	at ch.qos.logback.classic.util.ContextInitializer.getResource(ContextInitializer.java:141)
	at ch.qos.logback.classic.util.ContextInitializer.findURLOfDefaultConfigurationFile(ContextInitializer.java:130)
	at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:148)
	at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
	at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
	at org.slf4j.LoggerFactory.bind(LoggerFactory.java:144)
	at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:123)
	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:337)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:287)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:309)

I have logback-test.xml in src/test/resources, and have configured that as a source folder with an output of target/test-classes.

enter image description hereenter image description here

I even took at shot at editing the Classpath of the Run Configuration for JUnit for my project, and added the test-classes folder there, and it didn't help.

enter image description here

Is there something simple that I'm missing? I don't seem to recall having this issue in the past with other projects.

like image 297
IceBox13 Avatar asked Jan 22 '15 21:01

IceBox13


People also ask

Where is Logback xml in Eclipse?

When you run your project, configure the CLASSPATH and add the location of the logback. xml files by clicking on: Run As ->Run Configuration -> Classpath tab -> click on User Entries -> Advanced -> select Add Folder -> select the location of your logback. xml file and then -> OK -> Run.

Where is Logback Spring xml?

To configure Logback for a Spring Boot project via XML, create the logback. xml or logback-spring. xml file under the src/main/resources folder.


1 Answers

I checked my pom.xml, and logback-classic didn't have a specified version, and logback-core did. I set a property for the version and set them both to be the same.

like image 157
IceBox13 Avatar answered Oct 13 '22 23:10

IceBox13