本地项目打包后,将 jar
包打入本地仓库。然后,供给其他项目使用,发现项目中的相关依赖包并未引入,而且其他项目在运行时出现错误 NoClassDefFoundError
问题。
maven
打包时,默认不会将第三方依赖包打进来。可以在 pom.xml
中添加maven-assembly
插件实现… 打出的包里 xxxx-with-dependencies.jar
就是包含依赖包。
<build>
<plugins>
<!-- Maven Assembly Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>