facebook

Junit throws exception when using maven for classpath

  1. MyEclipse IDE
  2.  > 
  3. Maven for MyEclipse (Maven4MyEclipse)
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #287955 Reply

    aqbrown
    Member

    Since switching to maven for the project classpath, junit does not work in myeclipse 6.5 for me.

    It appears that there is a dependency on an older log4j version. My own poms reference a log4j that have the trace field, so I am wondering what is causing this …

    The exception is :

    junit.framework.AssertionFailedError: Exception in constructor: testSave (java.lang.NoSuchFieldError: TRACE
    at org.slf4j.impl.Log4jLoggerAdapter.log(Log4jLoggerAdapter.java:492)
    at org.apache.commons.logging.impl.SLF4JLocationAwareLog.trace(SLF4JLocationAwareLog.java:78)
    at org.springframework.core.CollectionFactory.createLinkedSetIfPossible(CollectionFactory.java:90)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.<init>(DefaultSingletonBeanRegistry.java:85)
    at org.springframework.beans.factory.support.AbstractBeanFactory.<init>(AbstractBeanFactory.java:142)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:133)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:144)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.<init>(DefaultListableBeanFactory.java:100)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.createBeanFactory(AbstractRefreshableApplicationContext.java:144)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:99)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:394)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:76)
    at edu.mit.academic.pe.dao.hibernate.HibernateProgramYearDAOTest.<init>(HibernateProgramYearDAOTest.java:38)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
    at junit.framework.TestSuite.createTest(TestSuite.java:131)
    at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
    at junit.framework.TestSuite.<init>(TestSuite.java:75)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:102)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:59)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    )
    at junit.framework.Assert.fail(Assert.java:47)
    at junit.framework.TestSuite$1.runTest(TestSuite.java:263)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

    #287971 Reply

    Riyad Kalla
    Member

    This is an interesting issue, but I wonder if the JUnit version is a red-herring? The reason I say that is your stack trace looks like:

    JUnit calls into your Hibernate DAO, your Hibernate DAO is called by Spring, Spring tries to use the Commons-Logging SLF4J impl, which is trying to use Log4J and the whole thing dies.

    If this project used to work in a non-Maven project, the trick is just checking the JAR versions you had before, and specifying those exact same dependencies for Maven, it will resolve them and you’ll get things working again.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Junit throws exception when using maven for classpath

You must be logged in to post in the forum log in