how to generate rpm using maven

I have a spring mvc maven application. I want to build an rpm out of it which can be deployed on the servers.
whats the process for generating rpms.
Also what i want is that the rpm bundles all the property files ie. for dev, staging, prod etc.
and when the rpm is unpacked and war deployed on the machine it at runtime selects the correct version to use... ie. for dev, prod or staging... depending on some environment variable.

Rohit BajajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RPMs are built using rpmbuild from source tarballs using .spec files
Maven has no instrumentation past invoking system command rpmbuild -ba SPECS/xyz.spec ,
Basically rpmbuild does same as maven - executes build scenario.
Here quick start:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rohit BajajAuthor Commented:
One more thing i want to know. I have heard of two approaches for deploying a project using rpm on a host
1) rpm contains all the files including property config files
2) rpm contains only the source code. It does not have any property files and they need to be supplied seperately

I am exploring option 2) But couldnt find any examples of it or how its actually done... how are the source code and config files separated

Jim CakalicSenior Developer/ArchitectCommented:
I haven't used it but a quick search revealed a maven rpm plugin. You'll find it here:

In my experience deploying application rpms on linux, the property files were included in the rpm but segregated in environment-specific directories under the root of the application install. The correct property file set was chosen at run-time using an environment variable. Example, if application installed to /opt/application and property files were in directories like:

and in the runtime environment of the application when it was started, an environment variable was set: APPENV=test then the application could load the correct properties from /opt/application/properties/$APPENV. Spring supports this kind of indirection for its PropertyPlaceholders.

CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

In Red Hat rpmbuild invokes maven where package needs it. This way you get source rpm too.
Rohit BajajAuthor Commented:
I built an rpm using maven plugin and then tried to unpack it on linux machine but nothing happened.
Here is my pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""




        <!-- Spring core & mvc -->


        <!-- CGLib for @Configuration -->


        <!-- Servlet Spec -->



        <!-- MySQL Driver -->



            <name>SpringSource Milestones Proxy</name>



                            <!--echo "installing done, performing db migration"-->
                            <!--su -l kuber -c /opt/kuber/current/scripts/>

Open in new window

On my computer i can see the war inside the path target/rpm/codeSnippet/buildroot/home/robinsu/tools/jetty/webapps
Also i am not a root user on the linux machine on which i am trying to install this rpm.
So i tried : rpm2cpio codeSnippet-1.0-null.x86_64.rpm | cpio -idv

I was expecting that this will place the war in the path : /home/robinsu/tools/jetty/webapps/snippet.war
But it didnt do it.
probably you meant -t where you typed -d for cpio. to list contents.
Rohit BajajAuthor Commented:
hmm i tried that it did something but still the file is not copied :
[robinsu@olympus101 webapps]$ ls
[robinsu@olympus101 webapps]$ cd ~/
[robinsu@olympus101 ~]$ ls
codeSnippet-1.0-null.x86_64.rpm  home  tools
[robinsu@olympus101 ~]$ rpm2cpio codeSnippet-1.0-null.x86_64.rpm | cpio -itv
-rw-r--r--   1 root     root     12652337 Oct  7 21:06 ./home/robinsu/tools/jetty/webapps/snippet.war
24713 blocks
[robinsu@olympus101 ~]$ cd ./home/robinsu/tools/jetty/webapps
[robinsu@olympus101 webapps]$ ls
[robinsu@olympus101 webapps]$ ls
[robinsu@olympus101 webapps]$ 

Open in new window

Infact if you see from above it deleted README file.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.