文末有超级大坑!!
使用spring boot 开发时,如果项目中引人了外部的包,在编译器中使用是没问题的,但是,当你想打包的时候,就会发现无法将lib下的jar一起打包到boot的fat jar中。会报错"系统软件包不存在";
解决方法很简单:
1.在根目录下建立一个lib包
2.配置一下本地依赖
(groupId/artifactId/version随便填一个即可,jar包用全名,不能用*号)
<dependency>
<groupId>com.xxx</groupId>
<artifactId>xxx</artifactId>
<version>v0.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/YOUR_JAR_NAME.jar</systemPath>
</dependency>
光是这样还不够!虽然打包时不报错了.但是运行时还是会提示"没有类".要如何才能把外部jar真正打包进去呢?
如下.
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> #下面这条不加也可以 <mainClass>io.xinshiyun.com.Application</mainClass <compilerArguments> #下面这条是需要根据lib文件夹的位置改写的,${project.basedir}是根目录. <extdirs>${project.basedir}/lib</extdirs> </compilerArguments> </configuration> </plugin> </plugins> <resources> <resource> #下面这条是需要根据lib文件夹的位置改写的,${project.basedir}是根目录 <directory>${project.basedir}/lib</directory> #打包后的文件目录,保留即可 <targetPath>BOOT-INF/lib/</targetPath> <includes> <include>**/*.jar</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <targetPath>BOOT-INF/classes/</targetPath> </resource> </resources> </build>
resources 这里有一个超级大坑!!!,加了它确实可以在打包时把外
部jar打如进去,但是!!!!!!
如果继续运行项目的话!,会报
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured.
Reason: Failed to determine a suitable driver class
APPLICATION FAILED TO START
***************************
Description:
Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured.
Reason: Failed to determine a suitable driver class
大意是数据源不对~!~!~!~!,我在数据库配置那里找了好久,一无所获,百度那些也都不对,,最后重新建个项目,把依赖一个个拖过去看时才发现.!!!
总结下:平时编程时注释掉resouces那一段,将要打包时恢复!!
世界又美好了一点!!