java.lang.ClassNotFoundException / NoClassDefFoundError for com/fasterxml/jackson/databind/ObjectMapper with Maven
当我尝试运行使用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
我在 Maven 存储库中拥有 Jackson 注释、databind(包含 ObjectMapper)和核心 JAR,位于 ~/.m2/repository/com/fasterxml/jackson/core/jackson-[packagename]/2.4.0 下。这是我的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 本身似乎找不到我需要的类。我做错了什么??谢谢!