java.lang.ClassNotFoundException / NoClassDefFoundError for com/fasterxml/jackson/databind/ObjectMapper with Maven

给你一囗甜甜゛ 提交于 2019-11-29 06:27:05

try to redo maven lifecycle goals:

mvn clean install -U

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!