how to generate rpm using maven

HI,
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.

Thanks
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.

gheistCommented:
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:
http://www.rpm.org/max-rpm/s1-rpm-build-creating-spec-file.html
0

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:
HI,
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

Thanks
0
Jim CakalicSenior Developer/ArchitectCommented:
I haven't used it but a quick search revealed a maven rpm plugin. You'll find it here:
http://www.mojohaus.org/rpm-maven-plugin/

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:
/opt/application/properties/dev
/opt/application/properties/prod
/opt/application/properties/test

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.

Regards,
Jim
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

gheistCommented:
In Red Hat rpmbuild invokes maven where package needs it. This way you get source rpm too.
0
Rohit BajajAuthor Commented:
HI,
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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.directi.code</groupId>
    <artifactId>snippet</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>snippet</name>
    <url>http://maven.apache.org</url>

    <properties>
        <!--<ENV>prod</ENV>-->
        <finalWarName>snippet</finalWarName>
        <java.version>1.7</java.version>
        <spring.version>4.2.1.RELEASE</spring.version>
        <cglib.version>2.2.2</cglib.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- Spring core & mvc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <type>jar</type>
            <scope>test</scope>
        </dependency>

        <!-- CGLib for @Configuration -->
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib-nodep</artifactId>
            <version>${cglib.version}</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>codemirror</artifactId>
            <version>5.6</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>

        <!-- Servlet Spec -->

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.6.2</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>4.2.1.RELEASE</version>
        </dependency>


        <!-- MySQL Driver -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.36</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

    </dependencies>

    <repositories>
        <repository>
            <id>springsource-milestones</id>
            <name>SpringSource Milestones Proxy</name>
            <url>https://oss.sonatype.org/content/repositories/springsource-milestones</url>
        </repository>
    </repositories>

    <build>
        <finalName>snippet</finalName>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <!--<resource>-->
                <!--<directory>src/main/resources/properties/${env.FLOCK_APPS_CONFIG}</directory>-->
            <!--</resource>-->
            <!--<resource>-->
                <!--<directory>src/main/resources/spring</directory>-->
            <!--</resource>-->
        </resources>

        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.2.11.v20150529</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webApp>
                        <contextPath>/</contextPath>
                    </webApp>
                    <httpConnector>
                        <!--host>localhost</host-->
                        <port>11001</port>
                    </httpConnector>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>rpm-maven-plugin</artifactId>
                <version>2.0</version>
                <extensions>true</extensions>
                <configuration>
                    <name>codeSnippet</name>
                    <copyright>2015</copyright>
                    <group>Application/Collectors</group>
                    <release>1</release>
                    <mappings>
                        <mapping>
                            <directoryIncluded>false</directoryIncluded>
                            <directory>/home/robinsu/tools/jetty/webapps</directory>
                            <username>tomcat</username>
                            <groupname>tomcat</groupname>
                            <sources>
                                <source>
                                    <location>${project.build.directory}/${finalWarName}.war</location>
                                </source>
                            </sources>
                        </mapping>
                    </mappings>
                    <!--<preinstallScriptlet>-->
                        <!--<scriptFile>src/main/scripts/pre_deploy.sh</scriptFile>-->
                        <!--<fileEncoding>utf-8</fileEncoding>-->
                    <!--</preinstallScriptlet>-->
                    <!--<postinstallScriptlet>-->
                        <!--<script>-->
                            <!--echo "installing done, performing db migration"-->
                            <!--su -l kuber -c /opt/kuber/current/scripts/post_deploy.sh-->
                        <!--</script>-->
                    <!--</postinstallScriptlet>-->
                    <needarch>noarch</needarch>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

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.
0
gheistCommented:
probably you meant -t where you typed -d for cpio. to list contents.
0
Rohit BajajAuthor Commented:
hmm i tried that it did something but still the file is not copied :
[robinsu@olympus101 webapps]$ ls
README.TXT
[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.
0
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.