每次开始build maven工程,都是本地IDE运行没有问题,打包后依赖的jar找不到class问题,原因是在build的时候,没有把依赖jar包含进来。只需要简单添加build部分即可:
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.17</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>2.2</version>
- <configuration>
- <appendAssemblyId>false</appendAssemblyId>
- <descriptorRefs>
- <descriptorRef>jar-with-dependencies</descriptorRef>
- </descriptorRefs>
- <archive>
- <manifest>
- <mainClass>com.framework.interf</mainClass>
- </manifest>
- </archive>
- </configuration>
- <executions>
- <execution>
- <id>make-assembly</id>
- <phase>package</phase>
- <goals>
- <goal>assembly</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <artifactId>maven-source-plugin</artifactId>
- <version>2.1</version>
- <configuration>
- <attach>true</attach>
- </configuration>
- <executions>
- <execution>
- <phase>compile</phase>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
Maven打包包含依赖
本文介绍如何在Maven项目中配置打包时包含所有依赖的jar文件。通过使用maven-assembly-plugin插件,并设置正确的配置参数,可以实现将依赖项一起打包到最终的jar文件中。
2893

被折叠的 条评论
为什么被折叠?



