我有一个Maven项目,在我的Mac上编译好 - 但是我第一次将它移到我的Windows 10 PC上,并且看到了我的JUnit测试的奇怪的编译问题。失败的是:
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)
这似乎是以下的传递依赖:
<dependency>
<groupId>com.kcthota</groupId>
<artifactId>emoji4j</artifactId>
<version>5.0</version>
</dependency>
由于mvn dependency:tree
包含:
[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
但我似乎无法理解为什么找不到这个类 - 如果我检查我的Maven存储库,那么JAR就存在了:
~\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.7.0\jackson-databind-2.7.0.jar
与JAR中的JavaType.class
类一样。
手动将jackson-databind
依赖项添加到我的POM似乎没有什么区别。
在测试编译过程中,Maven找不到这个类,在这台机器上?
编辑:此外,如果我使用调试日志记录运行Maven,我会看到:
[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
这似乎清楚地列出了杰克逊JAR。