Maven学习记录10 - RPM插件

1.web项目打rpm包

说明:

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

1.1 在pom 文件添加插件配置

    <!-- 配置服务器上tomcat的安装根目录 
    <properties>
        <tomcat_home>/usr/soft/tomcat</tomcat_home>
    </properties>
    -->
    <!-- 打包RPM包 mvn package -Dmaven.test.skip=true   -->
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>rpm-maven-plugin</artifactId>
        <version>2.1.5</version>
        <extensions>true</extensions>
        <executions>
            <execution>
                <goals>
                    <goal>rpm</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <prefix>${tomcat_home}</prefix><!-- tomcat目录  -->
            <copyright>2018, wwww.myron.com</copyright>
            <distribution>myron</distribution>
            <group>myron.com</group>
            <packager>myron</packager>
            <version>${project.version}</version>
            <autoRequires>true</autoRequires>
            <release>3</release>
            <requires>
                <require>java-1.7.0 >= 1.7</require>
            </requires>
            <mappings>
                <mapping>
                    <!-- 安装rpm后指向的web安装目录   -->
                    <directory>${tomcat_home}/webapps/${project.artifactId}</directory>
                    <filemode>755</filemode>
                    <username>root</username>
                    <groupname>root</groupname>
                    <sources>
                        <source>
                            <location>target/${project.artifactId}-${project.version}</location>
                        </source>
                    </sources>
                </mapping>
            </mappings>
            <!-- rpm安装后执行的脚本-->
            <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包)

说明:

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

2.1. pom文件

    <!--
    <properties>
        <java.version>1.8</java.version>
        <rpm.install.path>/usr/soft/app</rpm.install.path>
        <rpm.prefix>/usr/soft/app</rpm.prefix>
    </properties>
    -->
<build>
    <plugins>
        <!-- 打包RPM包: mvn package -Dmaven.test.skip=true   -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>rpm-maven-plugin</artifactId>
            <version>2.1.5</version>
            <extensions>true</extensions>
            <executions>
                <execution>
                    <goals>
                        <goal>rpm</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <prefix>${rpm.prefix}</prefix>
                <copyright>2018, wwww.myron.com</copyright>
                <distribution>myron</distribution>
                <group>myron.com</group>
                <packager>hello</packager>
                <version>${project.version}</version>
                <autoRequires>true</autoRequires>
                <release>3</release>

                <!-- yum依赖包 -->
                <requires>
                    <require>java-1.7.0 >= 1.7</require>
                </requires>

                <!--
                    项目中存在的文件和目录与在系统上安装RPM包时安装的文件和目录之间的映射。
                 -->
                <mappings>
                    <mapping>
                        <!-- 安装rpm后指向的服务器安装目录  -->
                        <directory>${rpm.install.path}/${project.artifactId}</directory>
                        <filemode>644</filemode>
                        <username>root</username>
                        <groupname>root</groupname>
                        <sources>
                            <source>
                                <location>target/${project.artifactId}-${project.version}.jar</location>
                            </source>
                        </sources>
                    </mapping>
                    <!-- 复制安装相关脚本命令 根据具体项目需要决定是否使用-->
                    <mapping>
                        <directory>${rpm.install.path}/${project.artifactId}/bin</directory>
                        <filemode>750</filemode>
                        <username>root</username>
                        <groupname>root</groupname>
                        <sources>
                            <source>
                                <location>src/bin</location>
                            </source>
                        </sources>
                    </mapping>

                    <!--配置软连接注册服务起停项目,相当于:ln -sf myapp.jar /etc/init.d/myapp)
                        启动: systemctl start myapp
                        停止: systemctl stop myapp
                        重启: systemctl restart myapp
                        查看日志: journalctl -u myapp-->
                    <mapping>
                        <directory>/etc/init.d</directory>
                        <filemode>750</filemode>
                        <username>root</username>
                        <groupname>root</groupname>
                        <sources>
                            <softlinkSource>
                                <location>${rpm.install.path}/${project.artifactId}/${project.artifactId}-${project.version}.jar</location>
                                <destination>${project.artifactId}</destination>
                            </softlinkSource>
                        </sources>
                    </mapping>
                </mappings>
                <preinstallScriptlet>
                    <script>echo "installing ${project.name} now"</script>
                </preinstallScriptlet>
                <postinstallScriptlet>
                    <!-- 通过软链接 配置"service demo-swagger2 " 相关操作命令启动-->
                    <!-- 使用上面softlinkSource配置替代
                    <script>
                        rm -f /etc/init.d/${project.artifactId};
                        ln -sf ${rpm.install.path}/${project.artifactId}/bin/startup.sh /etc/init.d/demo-swagger2;
                    </script>
                    -->
                </postinstallScriptlet>
                <preremoveScriptlet>
                    <script>
                        <!--rm -f /etc/init.d/${project.artifactId};-->
                        echo "uninstalling ${project.name} success";
                    </script>
                    <!-- 引用脚本方式
                    <scriptFile>src/main/scripts/preremove</scriptFile>
                    <fileEncoding>utf-8</fileEncoding>
                    -->
                </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


【原文链接】:https://blog.csdn.net/Myron_007/article/details/80899368

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
How to install RPM plugin: 1. Unzip the rpm.wcx and cpio.wcx to the Total Commander directory 2. In Total Commander, choose Configuration - Options 3. Open the 'Packer' page 4. Click 'Configure packer extension WCXs 5. type rpm as the extension 6. Click 'new type', and select the rpm.wcx 5. type cpio as the extension 6. Click 'new type', and select the cpio.wcx 7. Click OK What it does: This plugin allow you to browse rpm archives. Mandryka Yurij Brain group http://braingroup.nm.ru/ mailto:braingroup@hotmail.ru RPM plugin v.1.4 for Windows Commander. Copyright (c) 2000..2002 Mandryka Yurij ( Brain Group ) This plugin allow you to browse rpm archives with Windows Commander 4.0 or greater. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS OR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Any questions about plugin can be made via e-mail : braingroup@hotmail.ru and information about plugin can be found on Brain Group web site : http://braingroup.nm.ru/
### 回答1: Maven使用Tomcat8-maven-plugin插件可以将Web应用程序部署到Tomcat服务器上。以下是使用Tomcat8-maven-plugin插件的步骤: 1. 在pom.xml文件中添加以下插件配置: ``` <build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat8-maven-plugin</artifactId> <version>3.0-r1756463</version> <configuration> <url>http://localhost:8080/manager/text</url> <username>admin</username> <password>admin</password> <path>/myapp</path> </configuration> </plugin> </plugins> </build> ``` 2. 配置Tomcat服务器的管理用户和密码,以便插件可以将应用程序部署到服务器上。在Tomcat的conf/tomcat-users.xml文件中添加以下内容: ``` <role rolename="manager-gui"/> <user username="admin" password="admin" roles="manager-gui"/> ``` 3. 在命令行中执行以下命令将应用程序部署到Tomcat服务器上: ``` mvn tomcat8:deploy ``` 4. 如果需要重新部署应用程序,可以执行以下命令: ``` mvn tomcat8:redeploy ``` 5. 如果需要从Tomcat服务器中卸载应用程序,可以执行以下命令: ``` mvn tomcat8:undeploy ``` 以上就是使用Tomcat8-maven-plugin插件的基本步骤。需要注意的是,插件的版本号和Tomcat服务器的版本号需要匹配,否则可能会出现兼容性问题。 ### 回答2: Maven是一种基于Java平台的自动化构建工具,可以管理项目的依赖关系、编译、测试以及部署。Tomcat8-maven-plugin则是Maven插件的一种,用于将Maven项目打包成Web应用并且在Tomcat容器中运行。 Tomcat8-maven-plugin插件的使用方法如下: 1.在Maven项目的pom.xml文件中,添加如下插件配置: ``` <build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat8-maven-plugin</artifactId> <version>X.X.X</version> <configuration> <url>http://localhost:8080/manager/text</url> <server>TomcatServer</server> <path>/hello</path> </configuration> </plugin> </plugins> </build> ``` 其中,groupId和artifactId表示Tomcat8-maven-plugin插件的组ID和插件ID,version表示插件的版本号。configuration标签中的三个元素分别表示Tomcat管理页面的URL、Maven的服务器配置、Web应用在Tomcat容器中的访问路径。 2.运行Maven命令,将项目打包成war包: ``` mvn package ``` 3.将war包上传到Tomcat服务器,并在Tomcat管理页面上部署Web应用。 4.在Maven项目的根目录下,运行如下命令启动Tomcat容器: ``` mvn tomcat8:run ``` 5.在浏览器中输入http://localhost:8080/hello,即可访问Web应用。 总的来说,使用Tomcat8-maven-plugin插件能够简化项目的部署和运行,并且可以通过配置实现一些定制化的需求,适合于中小型Java Web项目的开发和维护。 ### 回答3: Maven是一个Java项目管理和构建工具,能够自动下载所需的依赖包、自动编译、测试和打包等,方便开发人员进行软件项目的快速开发。 Tomcat8-maven-plugin是一个Maven插件,它可用于将Web应用程序部署到Tomcat容器中。它能够快捷地将Web应用程序打包并部署到Tomcat 8服务器中,无需手动将WAR文件复制到Tomcat的webapps目录中。 它提供了许多配置选项,例如上下文路径、端口等参数,可以根据需要定制化自己的应用程序配置,使得部署更加灵活和方便。 使用Tomcat8-maven-plugin插件的步骤如下: 1. 在pom.xml文件中添加Tomcat8-maven-plugin配置 ```xml <build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat8-maven-plugin</artifactId> <version>3.0-r1756466</version> <configuration> <url>http://localhost:8080/manager/text</url> <server>tomcat8</server> <path>/myApp</path> </configuration> </plugin> </plugins> </build> ``` 2. 运行 Maven Build ``` mvn clean install ``` 以上是Tomcat8-maven-plugin插件的基本配置和使用方法,通过它能够简单高效地实现Web应用程序的部署和管理,方便开发人员进行项目开发和测试。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值