引入第三方包
1、不同的包引用可以通过 waven 方式引用 pom.xml 中配置,例:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
2、在maven中没有,的jar包引用方式,也是配置pom.xml文件
首先将jar包放入项目资源文件中
再配置pom.xml 文件
<!-- word 转 pdf -->
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>19.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/aspose-words-19.2-jdk16.jar</systemPath>
</dependency>
这时只是将包引入了,但是 maven 中还是没有,打包后的包文件也不会有这个jar
需要在配置一下 pom.xml
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
现在可以clean 然后在 install 就完成了
另附maven包库:https://mvnrepository.com/
通过实验,我的第三方包还是没有生成到打包文件中
参考其他方式,通过mvn命令
mvn install:install-file -Dfile=jar包的位置 -DgroupId=上面的groupId -DartifactId=上面的artifactId -Dversion=上面的version -Dpackaging=jar
去掉上面的pom.xml配置,通过正常导入包就可以可了
<!-- word 转 pdf -->
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>19.2</version>
</dependency>
你会发现这种方式只有自己的电脑可以使用,其他的就不行了,那么下面彻底解决打包问题
同样是修改 pom.xml 文件
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>19.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/aspose-words-19.2-jdk16.jar</systemPath>
</dependency>
配置 maven 打 jar 时修改清单文件,将本地 jar 写到 MANIFEST.MF 文件中,这样运行打包好的 jar 时就不会包找不到类的异常了(注意,多个 jar 的话,需要用空格隔开)
<!-- 打jar包的main方法配置 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.beyond.AutonaviApplication</mainClass>
</manifest>
<!-- 给清单文件添加键值对(配置文件外置)指定打包后的文件目录 -->
<manifestEntries>
<Class-Path>config/ config/lib/aspose-words-19.2-jdk16.jar</Class-Path>
</manifestEntries>
</archive>
<!--打包的时候忽略classes 路径下的配置文件 -->
<excludes>
<exclude>*.properties</exclude>
<exclude>*.xml</exclude>
<exclude>*.txt</exclude>
<exclude>templates/**</exclude>
</excludes>
</configuration>
</plugin>
现在重新打包,会发现lib库中存在本地包了,完成!