maven使用rpm-maven-plugin构建RPM包

rpm-maven-plugin 插件使用说明

1.web项目打rpm包

  • 说明:
    1. mvn package -Dmaven.test.skip=true 打包生成rpm包
    2. 安装rpm包:将编译后代码安装指定的tomat目录下(tomcat_home配置)
    3. 卸载rpm包:自动清除已经安装的文件

1.1 在pom 文件添加插件配置

    
    
    <plugin>
        <groupId>org.codehaus.mojogroupId>
        <artifactId>rpm-maven-pluginartifactId>
        <version>2.1.5version>
        <extensions>trueextensions>
        <executions>
            <execution>
                <goals>
                    <goal>rpmgoal>
                goals>
            execution>
        executions>
        <configuration>
            <prefix>${tomcat_home}prefix>
            <copyright>2018, wwww.myron.comcopyright>
            <distribution>myrondistribution>
            <group>myron.comgroup>
            <packager>myronpackager>
            <version>${project.version}version>
            <autoRequires>trueautoRequires>
            <release>3release>
            <requires>
                <require>java-1.7.0 >= 1.7require>
            requires>
            <mappings>
                <mapping>
                    
                    <directory>${tomcat_home}/webapps/${project.artifactId}directory>
                    <filemode>755filemode>
                    <username>rootusername>
                    <groupname>rootgroupname>
                    <sources>
                        <source>
                            <location>target/${project.artifactId}-${project.version}location>
                        source>
                    sources>
                mapping>
            mappings>
            
            <postinstallScriptlet>
                <script>echo "install success!"script>
            postinstallScriptlet>
        configuration>
    plugin>

1.2 linux中rpm-build的安装

yum install rpm-build

1.3 打包项目

mvn clean package -Dmaven.test.skip

1.4 rpm 安装与卸载

  • rpm文件位置:target/rpm/demo-xxx/RPMS/noarch/demo-xxx.rpm
安装:
rpm -ivh demo-xxx.rpm
卸载:
rpm -e demo-xxx

1.5 启动/停止

安装后起停项目与普通tomcat的web项目一致

2.非web项目打rpm包(针对可执行jar包)

  • 说明:
    1. 安装jar至服务器指定位置(其实就是复制jar)
    2. 配置软链接 注册服务 实现 systemctl start/stop/restart myapp 起停服务(linux 7)
    3. 安装相关脚本或插入服务相关脚本(根据实际需要)

1. pom文件补充下面配置

    
<build>
    <plugins>
        
        <plugin>
            <groupId>org.codehaus.mojogroupId>
            <artifactId>rpm-maven-pluginartifactId>
            <version>2.1.5version>
            <extensions>trueextensions>
            <executions>
                <execution>
                    <goals>
                        <goal>rpmgoal>
                    goals>
                execution>
            executions>
            <configuration>
                <prefix>${rpm.prefix}prefix>
                <copyright>2018, wwww.myron.comcopyright>
                <distribution>myrondistribution>
                <group>myron.comgroup>
                <packager>hellopackager>
                <version>${project.version}version>
                <autoRequires>trueautoRequires>
                <release>3release>
                <requires>
                    <require>java-1.7.0 >= 1.7require>
                requires>
                <mappings>
                    <mapping>
                        
                        <directory>${rpm.install.path}/${project.artifactId}directory>
                        <filemode>755filemode>
                        <username>rootusername>
                        <groupname>rootgroupname>
                        <sources>
                            <source>
                                <location>target/${project.artifactId}-${project.version}.jarlocation>
                            source>
                        sources>
                    mapping>
                    
                    <mapping>
                        <directory>${rpm.install.path}/${project.artifactId}/bindirectory>
                        <filemode>750filemode>
                        <username>rootusername>
                        <groupname>rootgroupname>
                        <sources>
                            <source>
                                <location>src/binlocation>
                            source>
                        sources>
                    mapping>

                    
                    <mapping>
                        <directory>/etc/init.ddirectory>
                        <filemode>750filemode>
                        <username>rootusername>
                        <groupname>rootgroupname>
                        <sources>
                            <softlinkSource>
                                <location>${rpm.install.path}/${project.artifactId}/${project.artifactId}-${project.version}.jarlocation>
                                <destination>${project.artifactId}destination>
                            softlinkSource>
                        sources>
                    mapping>
                mappings>
                <preinstallScriptlet>
                    <script>echo "installing ${project.name} now"script>
                preinstallScriptlet>
                <postinstallScriptlet>
                    
                    
                postinstallScriptlet>
                <preremoveScriptlet>
                    <script>
                        
                        echo "uninstalling ${project.name} success";
                    script>
                    
                preremoveScriptlet>
            configuration>
        plugin>
    plugins>
build>

2.2 linux中rpm-build的安装

yum install rpm-build

2.3 打包项目

mvn clean package -Dmaven.test.skip

2.4 rpm 安装与卸载

  • rpm文件位置:target/rpm/demo-xxx/RPMS/noarch/demo-xxx.rpm
安装:
rpm -ivh demo-xxx.rpm
卸载:
rpm -e demo-xxx

2.5 起停操作

使用Linux 7 以后服务新的启动方式

启动
systemctl start myapp
停止
systemctl stop myapp
重启
systemctl restart myapp
查看日志
journalctl -u myapp

参考文档:
1. 《maven之如何打rpm包》:https://blog.csdn.net/zxjxingkong/article/details/65442990
2. 《Maven RPM Plugin - Sample Configuration》 http://www.mojohaus.org/rpm-maven-plugin/example1.html
3. 《RPM包rpmbuild SPEC文件深度说明》 http://hlee.iteye.com/blog/343499

你可能感兴趣的:(maven,maven,rpm)