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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7883891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 21:49:47  来源:igfitidea点击:

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

javamavenmaven-2rpmrpm-maven-plugin

提问by blong

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

有谁知道使用 Maven 构建到 RPM 的任何 Web 应用程序?该RPM Maven插件提供的功能来构建一个RPM,但它的文档是缺乏。

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.

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

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>

    <!-- Hymanson JSON Processor -->
    <dependency>
        <groupId>org.codehaus.Hymanson</groupId>
        <artifactId>Hymanson-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>

Thanks for any/all help!

感谢您的任何/所有帮助!

采纳答案by 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.

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

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.

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

回答by Brett Okken

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.

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

回答by lzap

As far as I know Red Hatis working hard to deliver their Java projects (POM) in Fedora (RPM). Good example could be JBoss Application Server 7which 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.

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

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.

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

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.

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