- 打包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即可(文件最大那个)。java培训
- 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>