1. 程式人生 > >maven之如何打rpm包

maven之如何打rpm包

1. 思路

   利用rpm-maven-plugin外掛實現講javaweb或者java程式打包成rpm包,以便於RPM軟體倉庫管理

2.準備

   基於maven的javaweb專案

   linux主機或虛擬機器

3. 配置pom檔案

   在專案pom檔案的外掛配置中,增加 rpm-maven-plugin的配置

       <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>2017, zhuxj</copyright>
	            <distribution>zhuxj</distribution>
	            <group>zhuxj.com</group>
	            <packager>zhuxj</packager>
		    <version>${project.version}</version>
	            <autoRequires>true</autoRequires>
	            <release>1.el6</release>
	            <requires>
	                <require>java-1.7.0 >= 1.7</require>
	            </requires>
	            <mappings>
	                <mapping>
	                    <directory>${tomcat_home}/webapps/ROOT</directory><!-- web安裝目錄  -->
	                    <filemode>755</filemode>
	                    <username>tomcat</username>
	                    <groupname>tomcat</groupname>
	                    <sources>
	                        <source>
	                            <location>target/${project.artifactId}-${project.version}</location>
	                        </source>
	                    </sources>
	                </mapping>
	            </mappings>
	        </configuration>
	    </plugin>

4. linux中rpm-build的安裝

    此處以yum安裝為例

# yum install rpm-build

5. 打包

    遷出原始碼到linux主機,執行打包命令,即可在target/rpm/目錄下生成rpm包

# mvn  package