Example of a multi-module web application with the rpm-maven-plugin?

点点圈 提交于 2019-12-03 06:53:34
blong

So, it turns out the example that I gave in asking my question was quite wrong, which probably contributed to why I didn't get the complete answer I was looking for. What I was really looking for was an RPM to install to a server, that depended on a servlet container (i.e. Tomcat) and would install the included Web Applications (webapps) to Tomcat's webapps directory.

As such, here is the proper answer:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany.app</groupId>
    <artifactId>rpm-with-webapp</artifactId>

    <packaging>pom</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>${project.artifactId}</name>
    <url>http://maven.apache.org</url>

    <parent>
        <groupId>com.mycompany.app</groupId>
        <artifactId>application-master-pom</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <properties>
        <rpm.install.basedir>/srv/apache-tomcat-6.0.33</rpm.install.basedir>
        <rpm.install.webapps>${rpm.install.basedir}/webapps</rpm.install.webapps>
        <rpm.install.config>${rpm.install.basedir}/lib</rpm.install.config>
    </properties>

    <build>
        <extensions>
            <extension>
                <groupId>org.apache.maven.wagon</groupId>
                <artifactId>wagon-webdav</artifactId>
                <version>1.0-beta-2</version>
            </extension>
        </extensions>
    </build>

    <profiles>
        <profile>
            <id>build-rpm</id>
            <activation>
                <property>
                    <name>build-rpm</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>rpm-maven-plugin</artifactId>
                        <version>2.1-alpha-1</version>
                        <extensions>true</extensions>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>attached-rpm</goal>
                                </goals>
                                <phase>verify</phase>
                            </execution>
                        </executions>
                        <configuration>
                            <classifier>${rpm.classifier}</classifier>
                            <copyright>My Company</copyright>
                            <distribution>My Distribution</distribution>
                            <group>Applications/Internet</group>
                            <packager>${user.name}</packager>
                            <changelogFile>CHANGELOG</changelogFile>
                            <defaultDirmode>500</defaultDirmode>
                            <defaultFilemode>400</defaultFilemode>
                            <defaultUsername>tomcatuser</defaultUsername>
                            <defaultGroupname>tomcatuser</defaultGroupname>
                            <requires>
                                <require>apache-tomcat &gt;= 6.0.20-2</require>
                            </requires>
                            <mappings>
                                <!-- web app 1 (module #1) -->
                                <mapping>
                                    <directory>${rpm.install.webapps}/myWebApp1</directory>
                                    <sources>
                                        <source>
                                            <location>../path-to/myWebApp1/target/myWebApp1</location>
                                        </source>
                                    </sources>
                                </mapping>
                                <!-- web app 2 (module #2) -->
                                <mapping>
                                    <directory>${rpm.install.webapps}/myWebApp2</directory>
                                    <sources>
                                        <source>
                                            <location>../path-to/myWebApp2/target/unified-browser-widget</location>
                                        </source>
                                    </sources>
                                </mapping>

                                <!--  web app 3 (module #3) -->
                                <mapping>
                                    <directory>${rpm.install.webapps}/myWebApp3</directory>
                                    <sources>
                                        <source>
                                            <location>../path-to/myWebApp3/target/report-services</location>
                                        </source>
                                    </sources>
                                </mapping>
                            </mappings>
                                <postinstallScriptlet>
                                    <script>echo "WARNING: You may need to restart tomcat to ensure changes take effect."</script>
                                </postinstallScriptlet>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>
    </project>

The thing to note about this is that I was looking for a "multi-module" project, but really what I meant was packaging multiple related Web Applications into a single RPM. So, the proper configuration of this Maven build tells the RPM installer that Apache Tomcat is required and installs the webapps to the proper folder within Tomcat.

I would suggest making the rpm a separate project (even if part of a multi-module) and have it declare dependencies on the war(s) or additional artifacts provided by other projects.

As far as I know Red Hat is working hard to deliver their Java projects (POM) in Fedora (RPM). Good example could be JBoss Application Server 7 which is being packaged for Fedora right now. Its a big bunch of POM files that are being translated from POMs to RPMs using various techniques and RPM macros. Those RPMs are somehow Maven-compatible. I don't know many details, but feel free to ask on lists/irc channels.

But my message is - generally it is not possible to use a "translator" that would read a set of pom files and produced set of rpm files. There are snags, you have to package everything one by one by hand.

If your target is not to do it the clean way, you could distribute your app in an one big RPM. Its pretty easy to create binary-only rpm. But this is not the way how open-source is delivered in linux distributions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!