简体   繁体   中英

ClassNotFoundException thrown from Maven when compiling JUnit tests

I have a Maven project that compiles fine on my Mac - but I just moved it to my Windows 10 PC for the first time, and am seeing odd compilation issues for my JUnit tests. The failure is:

stringContainingEmojiWithTrailingSpaceIsDetected(com.myapp.EmojiUtilTest)  Time elapsed: 0.002 sec  <<< ERROR!
java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JavaType
        at emoji4j.EmojiUtils.removeAllEmojis(EmojiUtils.java:241)
        ...
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.JavaType
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

This appears to be a transitive dependency of:

<dependency>
    <groupId>com.kcthota</groupId>
    <artifactId>emoji4j</artifactId>
    <version>5.0</version>
</dependency>

As a mvn dependency:tree contains:

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ myapp ---
[INFO] com.craigotis.myapp:myapp:jar:0.0.1-SNAPSHOT
[INFO] +- com.google.code.gson:gson:jar:2.8.0:compile
[INFO] +- mysql:mysql-connector-java:jar:6.0.5:compile
[INFO] +- org.springframework:spring-jdbc:jar:4.3.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.3.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:4.3.4.RELEASE:compile
[INFO] |  \- org.springframework:spring-tx:jar:4.3.4.RELEASE:compile
[INFO] +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] +- org.apache.commons:commons-dbcp2:jar:2.0.1:compile
[INFO] |  +- org.apache.commons:commons-pool2:jar:2.2:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.7:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.7:compile
[INFO] +- junit:junit:jar:4.11:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- com.ibm.icu:icu4j:jar:58.1:compile
[INFO] \- com.kcthota:emoji4j:jar:5.0:compile
[INFO]    +- com.fasterxml.jackson.core:jackson-core:jar:2.7.0:compile
[INFO]    +- com.fasterxml.jackson.core:jackson-databind:jar:2.7.0:compile
[INFO]    |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.7.0:compile
[INFO]    \- com.googlecode.lambdaj:lambdaj:jar:2.3.3:compile
[INFO]       +- org.hamcrest:hamcrest-all:jar:1.1:compile
[INFO]       +- org.objenesis:objenesis:jar:1.2:compile
[INFO]       \- cglib:cglib-nodep:jar:2.2:compile

But I can't seem to understand why the class is not found - if I check my Maven repository, the JAR exists:

~\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.7.0\jackson-databind-2.7.0.jar

As does the JavaType.class class in the JAR.

Adding the jackson-databind dependency manually to my POM does not seem to make a difference.

What would cause this class to not be found by Maven during test compilation, on this machine?

Edit: Further, if I run Maven with debug logging, I see:

[DEBUG] test classpath classpath:
[DEBUG]   C:\Users\Craig\projects\myproject\target\test-classes
[DEBUG]   C:\Users\Craig\projects\myproject\target\classes
[DEBUG]   C:\Users\Craig\.m2\repository\com\google\code\gson\gson\2.8.0\gson-2.8.0.jar
[DEBUG]   C:\Users\Craig\.m2\repository\mysql\mysql-connector-java\6.0.5\mysql-connector-java-6.0.5.jar
[DEBUG]   C:\Users\Craig\.m2\repository\org\springframework\spring-jdbc\4.3.4.RELEASE\spring-jdbc-4.3.4.RELEASE.jar
[DEBUG]   C:\Users\Craig\.m2\repository\org\springframework\spring-beans\4.3.4.RELEASE\spring-beans-4.3.4.RELEASE.jar
[DEBUG]   C:\Users\Craig\.m2\repository\org\springframework\spring-core\4.3.4.RELEASE\spring-core-4.3.4.RELEASE.jar
[DEBUG]   C:\Users\Craig\.m2\repository\org\springframework\spring-tx\4.3.4.RELEASE\spring-tx-4.3.4.RELEASE.jar
[DEBUG]   C:\Users\Craig\.m2\repository\javax\transaction\javax.transaction-api\1.2\javax.transaction-api-1.2.jar
[DEBUG]   C:\Users\Craig\.m2\repository\org\apache\commons\commons-dbcp2\2.0.1\commons-dbcp2-2.0.1.jar
[DEBUG]   C:\Users\Craig\.m2\repository\org\apache\commons\commons-pool2\2.2\commons-pool2-2.2.jar
[DEBUG]   C:\Users\Craig\.m2\repository\commons-logging\commons-logging\1.1.3\commons-logging-1.1.3.jar
[DEBUG]   C:\Users\Craig\.m2\repository\org\apache\logging\log4j\log4j-api\2.7\log4j-api-2.7.jar
[DEBUG]   C:\Users\Craig\.m2\repository\org\apache\logging\log4j\log4j-core\2.7\log4j-core-2.7.jar
[DEBUG]   C:\Users\Craig\.m2\repository\junit\junit\4.11\junit-4.11.jar
[DEBUG]   C:\Users\Craig\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar
[DEBUG]   C:\Users\Craig\.m2\repository\com\ibm\icu\icu4j\58.1\icu4j-58.1.jar
[DEBUG]   C:\Users\Craig\.m2\repository\com\kcthota\emoji4j\5.0\emoji4j-5.0.jar
[DEBUG]   C:\Users\Craig\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.7.0\jackson-core-2.7.0.jar
[DEBUG]   C:\Users\Craig\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.7.0\jackson-databind-2.7.0.jar
[DEBUG]   C:\Users\Craig\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.7.0\jackson-annotations-2.7.0.jar
[DEBUG]   C:\Users\Craig\.m2\repository\com\googlecode\lambdaj\lambdaj\2.3.3\lambdaj-2.3.3.jar
[DEBUG]   C:\Users\Craig\.m2\repository\org\hamcrest\hamcrest-all\1.1\hamcrest-all-1.1.jar
[DEBUG]   C:\Users\Craig\.m2\repository\org\objenesis\objenesis\1.2\objenesis-1.2.jar
[DEBUG]   C:\Users\Craig\.m2\repository\cglib\cglib-nodep\2.2\cglib-nodep-2.2.jar
[DEBUG] provider classpath classpath:
[DEBUG]   C:\Users\Craig\.m2\repository\org\apache\maven\surefire\surefire-junit4\2.12.4\surefire-junit4-2.12.4.jar
[DEBUG]   C:\Users\Craig\.m2\repository\org\apache\maven\surefire\surefire-api\2.12.4\surefire-api-2.12.4.jar

Which seems to clearly list the Jackson JARs.

Color me very confused. I renamed my jackson directory in my .m2 folder and let Maven download new dependencies, and the error went away.

The sizes of the JARs are different, despite the insides seeming the same. New on the left, old on the right:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM