Package a Spring Boot App as RPM

Goals Package a Spring Boot Service as RPM Package Configure systemd integration Add install/uninstall hooks to create users, directories etc. Maven Setup <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.2</version> <relativePath/> </parent> <groupId>com.hascode</groupId> <artifactId>sample-app</artifactId> <version>1.0.0-SNAPSHOT</version> <name>sample-app</name> <properties> <java.version>11</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> (1) <groupId>de.dentrassi.maven</groupId> <artifactId>rpm</artifactId> <version>1.5.0</version> <executions> <execution> <goals> <goal>rpm</goal> </goals> </execution> </executions> <configuration> <packageName>sample-app</packageName> <skipSigning>true</skipSigning> <group>Application/Misc</group> <requires> <require>java-11-openjdk-headless</require> (2) </requires> <entries> <entry> (3) <name>/opt/sample-app</name> <directory>true</directory> <user>root</user> <group>root</group> <mode>0755</mode> </entry> <entry> (4) <name>/opt/sample-app/log</name> <directory>true</directory> <user>sample-app</user> <group>sample-app</group> <mode>0750</mode> </entry> <entry> (5) <name>/opt/sample-app/sample-app.jar</name> <file>${project.build.directory}/${project.build.finalName}.jar</file> <user>root</user> <group>root</group> <mode>0644</mode> </entry> <entry> (6) <name>/usr/lib/systemd/system/sample-app.service</name> <file>${project.basedir}/src/main/dist/sample-app.service</file> <mode>0644</mode> </entry> </entries> <beforeInstallation> (7) <file>${project.basedir}/src/main/dist/preinstall.sh</file> </beforeInstallation> <afterInstallation> <file>${project.basedir}/src/main/dist/postinstall.sh</file> </afterInstallation> <beforeRemoval> <file>${project.basedir}/src/main/dist/preuninstall.sh</file> </beforeRemoval> <license>All rights reserved</license> </configuration> </plugin> </plugins> </build> </project> ...

May 14, 2021 · 3 min · 567 words · Micha Kops