必须在Linux下运行,并且安装rpm-build
一、打开maven的setting文件
<settings>
[...]
<servers>
[...]
<server>
<id>gpg.passphrase</id>
<passphrase>clear or encrypted text</passphrase>
</server>
</servers>
</settings>
二、打开你的工程的pom.xml文件
<build>
[......]
<plugins>
[......]
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1.4</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>rpm</goal>
</goals>
</execution>
</executions>
<configuration>
<prefix>${rpm.prefix}</prefix>
<group>Application/Collectors</group>
<autoProvides>false</autoProvides>
<autoRequires>false</autoRequires>
<needarch>true</needarch>
<targetOS>${os.name}</targetOS>
<requires>
<require>filesystem</require>
<require>coreutils</require>
<require>setup</require>
<require>systemd</require>
</requires>
<mappings>
<mapping>
<filemode>744</filemode>
<directory>${rpm.prefix}/${project.artifactId}-${project.version}/lib/</directory>
<sources>
<source>
<location>${project.build.directory}/lib</location>
</source>
<source>
<location>${project.build.directory}//${project.artifactId}-${project.version}.jar</location>
</source>
</sources>
</mapping>
<mapping>
<filemode>744</filemode>
<directory>${rpm.prefix}/${project.artifactId}-${project.version}/conf/</directory>
<sources>
<source>
<location>src/main/resources</location>
<includes>
<include>storageaccess.properties</include>
<include>log4j.properties</include>
<include>commons-logging.properties</include>
</includes>
</source>
<source>
<location>src/scripts/storageaccess.service</location>
</source>
</sources>
</mapping>
<mapping>
<filemode>744</filemode>
<directory>${rpm.prefix}/${project.artifactId}-${project.version}/bin/</directory>
<sources>
<source>
<location>src/bin</location>
</source>
</sources>
</mapping>
</mappings>
<postinstallScriptlet>
<script>
chown -R tomcat:tomcat ${rpm.prefix}/${project.artifactId}-${project.version};
</script>
</postinstallScriptlet>
<postremoveScriptlet>
<script>
rm -rf ${rpm.prefix}/${project.artifactId}-${project.version};
rm -f /usr/local/bin/${project.artifactId};
rm -f /usr/lib/systemd/system/${project.artifactId}.service;
</script>
</postremoveScriptlet>
</configuration>
</plugin>
</plugins>
</build>
参数说明:http://www.mojohaus.org/rpm-maven-plugin/params.html