基于Maven 构建rpm包

本文介绍如何使用Maven的rpm-maven-plugin插件在Linux环境下构建RPM包。通过配置pom.xml文件指定插件版本及执行目标,设置文件权限、依赖项等参数,实现项目的自动化打包。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

必须在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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值