要打包第三方jar包,可以通过以下几种方式:
将第三方jar包手动放入项目的lib目录中,然后在pom.xml文件中使用<dependency> <groupId>com.example</groupId> <artifactId>example</artifactId> <version>1.0</version> <scope>system</scope> <systemPath>${project.basedir}/lib/example.jar</systemPath></dependency>使用Maven插件将第三方jar包安装到本地仓库中,然后在pom.xml文件中正常引入该依赖即可。mvn install:install-file -Dfile=path/to/example.jar -DgroupId=com.example -DartifactId=example -Dversion=1.0 -Dpackaging=jar<dependency> <groupId>com.example</groupId> <artifactId>example</artifactId> <version>1.0</version></dependency>使用Maven的assembly插件将项目及第三方jar包一起打包成一个可执行的jar包。在pom.xml文件中配置assembly插件:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <version>3.3.0</version> <configuration> <archive> <manifest> <mainClass>com.example.MainClass</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions></plugin>执行mvn clean package命令即可打包生成含有第三方jar包的可执行jar文件。




