Spring boot 生成可在Eclipse环境运行及单进程运行的maven pom.xml配置
在使用spring boot 时,调试时使用Eclipse,要求可在 Eclipse中直接运行,Eclipse编译时,缺省会将src/main/resource下的文件拷贝到target/classes目录,这样在调试环境可以正常运行。在进行打包时也能将resource下的配置文件、页面文件打包到可直接执行的jar包中。
同时,在target目录拷贝生成可直接运行的脚本文件,在该脚本文件中调用spring boot 可执行jar包。
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.3.2.RELEASE</version><!--$NO-MVN-MAN-VER$ -->
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<targetPath>.</targetPath>
<excludes>
<exclude>META-INF/resources/META-INF/MANIFEST.MF</exclude>
</excludes>
<includes>
<include>**/**</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<targetPath>${project.build.directory}</targetPath>
<includes>
<include>application.yml</include>
<include>logback.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources/META-INF/script</directory>
<targetPath>${project.build.directory}</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
</build>
1、几个关键文件位置
(1)脚本start.bat(或start.sh),位于:
src/main/resources/META-INF/script
内容:
java -jar spring-boot-application.jar --server.port=8080 > nohup.log 2>&1
(2)pplication.yml, logback.yml位置:
src/main/resources
2、target输出目录结构(支持直接脚本运行):
- start.bat
- spring-boot-application.jar
- application.yml
- logback.yml(日志配置,可选)
3、Spring boot 可执行jar包目录结构:
- com(应用classes)
- lib(依赖jar包)
- org(Spring boot 类)
- META-INF(页面资源)包括resources目录,resources下内容等同于普通WEB项目WebContent下的内容。
- application.yml(应用参数配置)
- logback.xml(日志配置)
- 其他配置目录或文件
target/classes目录结构
与Spring boot 可执行jar包目录结构同。