springboot 打jar包后启动,resource下配置文件找不到和lib下jar包打包问题解决

我会带着你远行 2022-03-09 03:51 2335阅读 0赞

首先把项目中那些乱七八糟的pom的依赖,插件都去掉,因为再这上面吃了大亏….都不知道为什么那些东西会存在,自己的项目也用不上的,揪心,整了2小时….

先上图,项目结构如图所示:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTAzOTg3NzE_size_16_color_FFFFFF_t_70

项目中的引入方式为:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTAzOTg3NzE_size_16_color_FFFFFF_t_70 1

在此进行service.xml文件的引入,在本地run/debug启动都没有什么问题,但是打成jar包之后启动就是找不到文件,修改pom文件如下:

  1. <resources>
  2. <resource>
  3. <directory>src/main/resources</directory>
  4. <includes>
  5. <include>**/*</include>
  6. </includes>
  7. <filtering>true</filtering>
  8. </resource>
  9. </resources>

进行文件的打包.

2.lib下jar包的打包问题

结构如下:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTAzOTg3NzE_size_16_color_FFFFFF_t_70 2

lib下面有两个jar包

1.在pom中的引入依赖

  1. <dependency>
  2. <groupId>com.bocom</groupId>
  3. <artifactId>core</artifactId>
  4. <version>1.6.2</version>
  5. <scope>system</scope>
  6. <systemPath>${basedir}/lib/xx.jar</systemPath>
  7. </dependency>
  8. <dependency>
  9. <groupId>com.bocom</groupId>
  10. <artifactId>service</artifactId>
  11. <version>1.6.2</version>
  12. <scope>system</scope>
  13. <systemPath>${basedir}/lib/xx2.jar</systemPath>
  14. </dependency>

2.修改build,结合上面的,最终成为:

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.springframework.boot</groupId>
  5. <artifactId>spring-boot-maven-plugin</artifactId>
  6. <configuration>
  7. <fork>true</fork>
  8. </configuration>
  9. </plugin>
  10. <plugin>
  11. <groupId>org.apache.maven.plugins</groupId>
  12. <artifactId>maven-compiler-plugin</artifactId>
  13. <configuration>
  14. <source>1.7</source>
  15. <target>1.7</target>
  16. <encoding>UTF-8</encoding>
  17. <compilerArguments>
  18. <extdirs>src\main\webapp\WEB-INF\lib</extdirs>
  19. </compilerArguments>
  20. </configuration>
  21. </plugin>
  22. </plugins>
  23. <resources>
  24. <resource>
  25. <targetPath>BOOT-INF/lib/</targetPath>
  26. <directory>${basedir}/lib/</directory>
  27. <includes>
  28. <include>**/*.jar</include>
  29. </includes>
  30. </resource>
  31. <resource>
  32. <directory>src/main/resources</directory>
  33. <includes>
  34. <include>**/*</include>
  35. </includes>
  36. <filtering>true</filtering>
  37. </resource>
  38. </resources>
  39. </build>

就可以了,打成jar包完美运行

发表评论

表情:
评论列表 (有 0 条评论,2335人围观)

还没有评论,来说两句吧...

相关阅读