springboot maven

时间:2023-11-23 22:11:50

更多信息请从官网获取https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE

1.parent基于自己项目而非spring-boot-starter-parent

  目前解决方案

    (1)所有的springboot依赖显示写出版本号

    (2)plugin显示写出执行目标repackage

 <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.0.1.RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.1.RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.0.1.RELEASE</version>
<scope>test</scope>
</dependency> <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.1.RELEASE</version>
<configuration>
<classifier>exec</classifier>
<executable>true</executable>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>

note: <classifier>exec</classifier>该标签作用是如果有其他项目依赖该项目时,会打成两个jar,一个是xxx.jar(别的项目依赖用)另一个是xxx-exec.jar(部署执行用)

2.idea run没问题,打成jar包执行报资源文件找不到

  目前解决方案是拷贝一份资源文件到classes目录下即可

<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration> </execution>
</executions>
</plugin>

如果idea run也报资源文件找不到

  (1)检查该文件是否存在resources文件夹内

(2)检查resources文件夹是否为Resources Root 。否则右键Mark Directory As --> Resources Root 即可