Maven Recipe: Delivering applications as RPMs

In the Java world, the standard unit of delivery is the jar/war/(x)ar file. For applications which don’t fit the ‘single file’ delivery model, there is no standard alternative.  To provide a solution, I will show you how to package your application with Maven as an RPM.

As we are talking about Maven, the solution starts with finding the right plugin – in our situation the rpm-maven-plugin. We include the plugin as follows:


The goal we need to execute is rpm – and it attaches itself to the package phase by default – so far so good.

The configuration that is usually done in a RPM spec file is done inside the plugin’s configuration block. First, we list some required descriptive elements:

  <copyright>2010, NoBody</copyright>
  <description>Maven Recipe: RPM Package.</description>

Now we get to the core of the RPM – listing the files to deploy. As we want to deploy our application’s classes and the ones from our dependencies, we create a mapping:


This is a very compact way of declaring that we want all dependencies – the dependency tag – and our primary build artifact – the artifact tag – to be deployed to the lib directory of our application.

The next step is to take the file which is checked into source control and deploy it as a sample file in the conf directory, so that we have a reference at hand when configuring the application:


Using location and destination we have absolute control over what is included and where it is placed. Also note the usage of the configuration tag, which translates in to the %config RPM macro, which means that changes to the file are preserved when updating or removing RPM  ( details on the RPM %config macro ).

Last, we need to generate an empty logs directory for our application. This is done simply by declaring a mapping with no sources.


Right now we can build a RPM out of our application. I’ve added hibernate 3.3.2.GA as a dependency, since it brings in a few transitive dependencies.

robert@neghvar:~/workspace/rpm-package> mvn clean package
[INFO] Scanning for projects...                          
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Recipe: RPM Package                                      
[INFO]    task-segment: [clean, package]                                       
[INFO] ------------------------------------------------------------------------
[INFO] Wrote: /home/robert/workspace/rpm-package/target/rpm/rpm-package/RPMS/rpm-package-0.0.1-SNAPSHOT20100520205409.noarch.rpm   
[INFO] ------------------------------------------------------------------------                                                     
[INFO] BUILD SUCCESSFUL                                                                                                             
[INFO] ------------------------------------------------------------------------                                                     
[INFO] Total time: 5 seconds                                                                                                        
[INFO] Finished at: Thu May 20 23:54:11 EEST 2010                                                                                   
[INFO] Final Memory: 15M/174M                                                                                                       
[INFO] ------------------------------------------------------------------------

Let’s verify that the RPM file indeed contains all that we asked it to:

robert@neghvar:~/workspace/rpm-package> rpm -qlp /home/robert/workspace/rpm-package/target/rpm/rpm-package/RPMS/rpm-package-0.0.1-SNAPSHOT20100520205409.noarch.rpm

We have reached our goal of building an RPM with our applications dependencies, classes and configuration files. By using the rpm-maven-plugin we have managed to keep using Maven as our build tool interface, and also reused the information available in the POM file for declaring dependencies.

The complete source code for this article is available at–RPM-Package . If you have any suggestions or corrections, please comment. Or better yet, fork me.



  1. […] been lead to a page describing how RPMs can be built using a Maven […]

  2. Nacho said

    Thanks a lot dude 🙂

    • Robert said

      You’re welcome 🙂

  3. Binod Suman said

    Hi Robert,

    Thanks for sharing this good tutorial. I tried to search lot but didnt get any good example stright forward.

    Thanks Again. 🙂

    Binod Suman

    • Robert said

      You’re welcome, glad I could help.

  4. Thanks a lot for sharing this!

    • Robert said

      You’re welcome.

  5. Jamila said


    I read you article and it’s very interresting. I want to know if you have already use “RPM Package Dependency Management” and provides?
    Because I want to create a container with an rpm and virtual dependecies to other rpm …

    Thanks in advance


  6. shakeer said

    what is ${}/

    • Robert said

      ${app.home} is an arbitrary location I define to be the root of the installation.
      ${} is the standard Maven directory where the files are placed during the build.

      I suggest you take the GitHub project for a spin, there’s a link at the end of the article.

  7. Is there any dependency on Linux? I mean I am following your tutorial and for some reason it is failing. Obviously maven is os independent, rpm plugin I haven’t found any restriction on plugin’s page, and all linux paths I converted to windows. Not sure what might go wrong.
    One more qutestion: When you say “${app.home} is an arbitrary location I define to be the root of the installation” – does that mean that if the rpm package is installed that that is the location where the installation lives?
    Thanks for clarification and sorry, I am not that familiar with rpm

    • Robert said

      The plugin depends on a rpmbuild binary being available. I’m not sure you can get than on Windows.

      As for the “${app.home}” location, that’s the location where the package will be installed in the filesystem when the RPM is installed.

  8. Himanshu said

    Getting …
    [ERROR] Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.0.1:rpm (generate-rpm) on project : RPM query for default vendor returned: ’1′ executing ‘cmd.exe
    /X /C “rpm -E %{_host_vendor}”‘ -> [Help 1]
    Tried almost everything, but still the same error…

    • Robert said

      It seems that you need the rpm tooling installed. On Linux it’s pretty easy, but I have no idea if it can be done on Windows

  9. Getting following Error:

    Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.0.1:rpm (default) on project xxxxxx: The parameters ‘group’ for goal org.codehaus.mojo:rpm-maven-plugin:2.0.1:rpm are missing or invalid -> [Help 1]

  10. If pom.xml is creating jar package, how do I include jar iinto rpm?

  11. Christian said

    How can I install and run your created rpm?
    yum localinstall ?

  12. dansharf said

    When I run rpm -i
    I get this message on Mac El Capitan:
    error: Failed dependencies:
    /opt/app is needed by rpm-package-0.0.1-SNAPSHOT20160819204529.x86_64
    What might be a reason for that? Thanks

    • Robert said

      Looks like an incorrect dependency declared by your RPM . Look for mistakes in the rpm-maven-plugin configuration block.

  13. Srini said


    when i am running the same sample in eclipse on my windows , build is failed and got the below error

    [WARNING] rpm version string truncated to 0.0.1
    [WARNING] ‘rpm’ is not recognized as an internal or external command,
    [WARNING] operable program or batch file.
    [INFO] ————————————————————————
    [INFO] ————————————————————————
    [INFO] Total time: 2.774 s
    [INFO] Finished at: 2016-09-27T17:51:07+05:30
    [INFO] Final Memory: 13M/210M
    [INFO] ————————————————————————
    [ERROR] Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.0.1:rpm (default) on project rpm-package: RPM query for default vendor returned: ‘1’ executing ‘cmd.exe /X /C “rpm -E %{_host_vendor}”‘ -> [Help 1]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1]

    • Robert said

      In order to package RPMs you need the ‘rpm’ binary installed on your system. I’m not sure if that’s possible in Windows.

  14. Amal said

    When i add the below configuration, the plugin takes all the files in the location, but i only need the jar files. How can i do that?


RSS feed for comments on this post · TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: