NoClassDefFoundError of com/fasterxml/jackson/databind/ObjectMapper with Maven

后端 未结 2 474
没有蜡笔的小新
没有蜡笔的小新 2020-12-19 12:02

This is a similar question as the one here, which is unfortunately unresolved yet.

If you want to debug the code, here is the GitHub repo.

相关标签:
2条回答
  • 2020-12-19 12:33
    <dependency>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-xml</artifactId>
    <version>2.8.5</version>
    </dependency>
    
    0 讨论(0)
  • 2020-12-19 12:42

    As I answered here


    The default maven plugin doesn't build a fat jar with dependencies.

    To build a jar bundled with its dependencies so that we can execute it with java -jar, we can use maven-assembly-plugin, which packages the jar with the name xxx-jar-with-dependencies.jar.

    Here is a sample pom.xml

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>com.example.yourMain</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id> <!-- this is used for inheritance merges -->
                        <phase>package</phase> <!-- bind to the packaging phase -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    

    Now you should be able to run your jar with

    java -jar xxx-jar-with-dependencies.jar
    
    0 讨论(0)
提交回复
热议问题