1. 打包jar
首先在需要打包的pom
里添加代码:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>cn.xx.Aes.xxEncode</mainClass> </manifest> <manifestEntries> <Class-Path>.</Class-Path> </manifestEntries> </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> </plugins> </build>
然后直接使用maven的clean
和package
即可打包,打包好后,在target
文件夹里直接复制生成好的jar
即可(文件最大那个)。
2. SpringBoot引入jar包
最后附上SpringBoot
引用jar
包的方式,首先在src
同级目录增加lib
文件夹,并复制打包好的jar
包到此目录:
选择jar包,右键 ->Add as Library
最后,在pom
文件添加依赖,代码如下:
<dependency> <groupId>cn.com.xxx</groupId> <artifactId>xxx</artifactId> <scope>system</scope> <systemPath>${project.basedir}/lib/xxx.jar</systemPath> </dependency>