尝试运行使用 jackon 的 ObjectMapper 类的 java 程序时出现以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
at com.inin.dynamotransfer.DynamoTransfer.importData(DynamoTransfer.java:133)
at com.inin.dynamotransfer.DynamoTransfer.main(DynamoTransfer.java:67)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 2 more
我在 ~/.m2/repository/com/fasterxml/jackson/core/jackson-[packagename]/2.4.0 下的 Maven 存储库中有 Jackson 注释、数据绑定(包含 ObjectMapper)和核心 JAR。这是我的 pom.xml 的依赖项部分:
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
这是我的类路径:
:/Users/myusername/Library/Java/Extensions:/Library/Java/Extensions:/Users/myusername/.m2/repository
所以 Maven 对这些 JAR 了如指掌——在哪里获取 em,在哪里放置 em,等等——但 java 本身似乎找不到我需要的类。我究竟做错了什么??谢谢!