使用 rpm-maven-plugin 的多模块 Web 应用程序示例?

发布于 2024-12-11 11:04:09 字数 6003 浏览 0 评论 0原文

有谁知道使用 Maven 构建 RPM 的 Web 应用程序吗? RPM Maven 插件 提供了构建 RPM 的功能,但缺少文档。

具体来说,我正在寻找一个包含多个模块的示例,即 Chapter 8. 多模块项目,来自“Maven by Examples”系列。

仅包含单个模块的示例是:

<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>my-webapp</artifactId>
  <packaging>war</packaging>
  <version>1.0-SOME-SNAPSHOT</version>
  <name>my-webapp</name>
  <url>http://maven.apache.org</url>

  <properties>
    <rpm.install.basedir>/opt/tomcat6</rpm.install.basedir>
    <rpm.install.webapps>${rpm.install.basedir}/webapps</rpm.install.webapps>
    <rpm.install.config>${rpm.install.basedir}/lib</rpm.install.config>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <!-- Servlet -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp.jstl</groupId>
        <artifactId>jstl-api</artifactId>
        <version>1.2</version>
    </dependency>       
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jstl-impl</artifactId>
        <version>1.2</version>
    </dependency>

    <!-- Jackson JSON Processor -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.8.1</version>
    </dependency>
  </dependencies>

  <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>
          </execution>
        </executions>
        <configuration>
          <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>tomcat6</defaultUsername>
          <defaultGroupname>tomcat6</defaultGroupname>
          <requires>
            <require>apache-tomcat &gt;= 6.0.20-2</require>
          </requires>
          <mappings>

            <!-- webapps deployment -->
            <mapping>
              <directory>${rpm.install.webapps}/${project.artifactId}</directory>
              <sources>
                <source>
                  <location>target/${project.artifactId}-${project.version}</location>
                </source>
              </sources>
            </mapping>

            <!-- configuration files -->
            <mapping>
              <directory>${rpm.install.config}</directory>
              <configuration>true</configuration>
              <sources>
                <source>
                  <location>src/main/resources/my-webapp.jdbc.properties.sample</location>
                </source>
                <source>
                  <location>src/main/resources/my-webapp.runtime.properties</location>
                  <destination>my-webapp.runtime.properties.sample</destination>
                </source>
              </sources>
            </mapping>

            <!-- (Optional) Create other necessary directory structure -->
            <mapping>
              <directory>${rpm.install.basedir}/my-webapp-workspace</directory>
              <filemode>750</filemode>
              <username>tomcatuser</username>
              <groupname>tomcatuser</groupname>
            </mapping>

          </mappings>

          <!-- (Optional) -->
          <preinstallScriptlet>
            <scriptFile>src/main/scripts/rpm/pre-install.sh</scriptFile>
          </preinstallScriptlet>
          <!-- (Optional) -->
          <postinstallScriptlet>
            <script>echo "WARNING: Restart tomcat to ensure changes take effect."</script>
          </postinstallScriptlet>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

感谢任何/所有帮助!

Does anyone know of any web applications that are built with Maven to an RPM? The RPM Maven Plugin provides the functionality to build to an RPM, but it's documentation is lacking.

Specifically, I'm looking for an example that would include multiple modules, i.e. Chapter 8. A Multi-module Project, from the "Maven by Example" series.

An example with only a single module would be:

<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>my-webapp</artifactId>
  <packaging>war</packaging>
  <version>1.0-SOME-SNAPSHOT</version>
  <name>my-webapp</name>
  <url>http://maven.apache.org</url>

  <properties>
    <rpm.install.basedir>/opt/tomcat6</rpm.install.basedir>
    <rpm.install.webapps>${rpm.install.basedir}/webapps</rpm.install.webapps>
    <rpm.install.config>${rpm.install.basedir}/lib</rpm.install.config>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <!-- Servlet -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp.jstl</groupId>
        <artifactId>jstl-api</artifactId>
        <version>1.2</version>
    </dependency>       
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jstl-impl</artifactId>
        <version>1.2</version>
    </dependency>

    <!-- Jackson JSON Processor -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.8.1</version>
    </dependency>
  </dependencies>

  <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>
          </execution>
        </executions>
        <configuration>
          <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>tomcat6</defaultUsername>
          <defaultGroupname>tomcat6</defaultGroupname>
          <requires>
            <require>apache-tomcat >= 6.0.20-2</require>
          </requires>
          <mappings>

            <!-- webapps deployment -->
            <mapping>
              <directory>${rpm.install.webapps}/${project.artifactId}</directory>
              <sources>
                <source>
                  <location>target/${project.artifactId}-${project.version}</location>
                </source>
              </sources>
            </mapping>

            <!-- configuration files -->
            <mapping>
              <directory>${rpm.install.config}</directory>
              <configuration>true</configuration>
              <sources>
                <source>
                  <location>src/main/resources/my-webapp.jdbc.properties.sample</location>
                </source>
                <source>
                  <location>src/main/resources/my-webapp.runtime.properties</location>
                  <destination>my-webapp.runtime.properties.sample</destination>
                </source>
              </sources>
            </mapping>

            <!-- (Optional) Create other necessary directory structure -->
            <mapping>
              <directory>${rpm.install.basedir}/my-webapp-workspace</directory>
              <filemode>750</filemode>
              <username>tomcatuser</username>
              <groupname>tomcatuser</groupname>
            </mapping>

          </mappings>

          <!-- (Optional) -->
          <preinstallScriptlet>
            <scriptFile>src/main/scripts/rpm/pre-install.sh</scriptFile>
          </preinstallScriptlet>
          <!-- (Optional) -->
          <postinstallScriptlet>
            <script>echo "WARNING: Restart tomcat to ensure changes take effect."</script>
          </postinstallScriptlet>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

Thanks for any/all help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

oО清风挽发oО 2024-12-18 11:04:09

所以,事实证明,我在提出问题时给出的例子是完全错误的,这可能是我没有得到我正在寻找的完整答案的原因。我真正想要的是一个安装到服务器的 RPM,它依赖于 servlet 容器(即 Tomcat)并将包含的 Web 应用程序(webapps)安装到 Tomcat 的 webapps 目录。

因此,正确的答案如下:

<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 >= 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>

需要注意的是,我正在寻找一个“多模块”项目,但实际上我的意思是将多个相关的 Web 应用程序打包到一个 RPM 中。因此,此 Maven 构建的正确配置会告诉 RPM 安装程序需要 Apache Tomcat,并将 Web 应用程序安装到 Tomcat 中的正确文件夹中。

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

高跟鞋的旋律 2024-12-18 11:04:09

我建议将 rpm 制作为一个单独的项目(即使是多模块的一部分),并让它声明对战争或其他项目提供的其他工件的依赖关系。

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.

水水月牙 2024-12-18 11:04:09

据我所知,红帽正在努力在 Fedora (RPM) 中交付他们的 Java 项目 (POM)。 JBoss Application Server 7 就是一个很好的例子,它现在正在为 Fedora 打包。它是一大堆 POM 文件,正在使用各种技术和 RPM 宏从 POM 转换为 RPM。这些 RPM 在某种程度上与 Maven 兼容。我不知道很多细节,但请随时在lists/irc频道上询问。

但我的信息是 - 通常不可能使用“翻译器”来读取一组 pom 文件并生成一组 rpm 文件。有一些障碍,你必须手工将所有东西一一打包。

如果您的目标不是以干净的方式完成它,您可以以一个大的 RPM 分发您的应用程序。创建纯二进制 rpm 非常容易。但这并不是 Linux 发行版中提供开源的方式。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文