【问题标题】:Multi module maven project not being deployed on OpenShift (S2I)未在 OpenShift (S2I) 上部署多模块 maven 项目
【发布时间】:2017-11-07 14:02:12
【问题描述】:

我正在开发一个 maven 多模块应用程序,它由两个模块组成:

  1. 常见
  2. 网页应用 我的项目结构如下:

    -(root)pom
        -Common  
        -Webapp
    

我们正在使用带有 S2I(源到映像)部署的 openshift Web 控制台。我们选择的图像是 Jboss Eap。提供 git 存储库后,Openshift 开始创建所需的资源。它使用 maven 成功编译和安装了我们的模块,但是它没有将它部署在 Jboss 的独立文件夹中。查看构建日志,我们可以在日志末尾检查所有正在检索的依赖项和构建成功。但是没有在图像 jboss 文件夹上部署工件。我们可以通过查看日志或使用控制台检查 pod 文件来确认这一点。

这个项目在 bitbucket 上

根 pom.xml

    <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.test.parent</groupId>
        <artifactId>parent</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <packaging>pom</packaging>

        <name>:: Parent ::</name>
        <description>Parent POM for some app</description>


        <modules>
            <module>Common</module>
            <module>Webapp</module>
        </modules>

    </project>

常见的pom:

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

        <parent>
            <groupId>com.test.parent</groupId>
            <artifactId>parent</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </parent>

        <groupId>com.test.common</groupId>
        <artifactId>Common</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <packaging>jar</packaging>

        <name>Common module</name>
        <description>Module for common elements that exist between projects</description>


        <build>
            <finalName>${project.artifactId}</finalName>
            <plugins>
                <!-- Compiler plugin enforces Java 1.8 compatibility and activates annotation
                    processors -->
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>

        <dependencies>
            ...
        </dependencies>

    </project>

最后是网络 pom:

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

        <parent>
            <groupId>com.test.parent</groupId>
            <artifactId>parent</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </parent>

        <groupId>com.test.external</groupId>
        <artifactId>Webapp</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>war</packaging>

        <name> Web</name>
        <description>web module</description>

        <properties>
            <!-- Explicitly declaring the source encoding eliminates the following
                message: -->
            <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
                resources, i.e. build is platform dependent! -->
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

            <!-- JBoss dependency versions -->

            <version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>

            <version.jboss.spec.javaee.7.0>1.0.3.Final</version.jboss.spec.javaee.7.0>

            <!-- other plug-in versions -->
            <version.war.plugin>2.1.1</version.war.plugin>

            <!-- maven-compiler-plugin -->
            <maven.compiler.target>1.8</maven.compiler.target>
            <maven.compiler.source>1.8</maven.compiler.source>
        </properties>

        <build>
            <!-- Set the name of the WAR, used as the context root when the app
                is deployed -->
            <finalName>${project.artifactId}</finalName>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>${version.war.plugin}</version>
                    <configuration>
                        <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                    </configuration>
                </plugin>
            </plugins>
        </build>



        <dependencies>
            ...
            <dependency>
                <groupId>com.test.common</groupId>
                <artifactId>Common</artifactId>
                <version>1.0.0-SNAPSHOT</version>
                <type>jar</type>
            </dependency>


        </dependencies>


    </project>

有人能做到这一点吗?

【问题讨论】:

  • 我尝试将 maven 参数包含在此处,但没有成功:stackoverflow.com/questions/39104003/…
  • 我缺乏部署 Java 的任何真正知识,但这可能有助于解释所需的内容。 blog.openshift.com/maven-multi-module-projects-and-openshift
  • oc set env bc/yourappname --list 能得到什么?
  • 谢谢大家。目的是尽可能快地部署,而无需创建自定义脚本或图像。我们可以在两分钟内从 Web 控制台进行 S2I。缺点是 S2I 适用于 CI 和 CD,因为您可能需要在所有 pod 上部署相同的工件。

标签: java maven jboss openshift s2i


【解决方案1】:

我认为有一个更好的方法,那就是在你的 web pom.xml 中使用 openshift 配置文件。这可以追溯到它在 V2 中完成的方式。在构建期间将调用的 openshift 配置文件中,将 .war 文件复制到部署目录中。我注意到的唯一区别是部署目录被命名为target 而不是webapps,但我没有做任何详细的测试,因为target 似乎工作。例如:

<profiles>
  <profile>
    <!-- When built in OpenShift the openshift profile will be used when invoking  mvn. -->
    <!-- Use this profile for any OpenShift specific customization your app  will need. -->
    <!-- By default that is to put the resulting archive into the deployments folder. -->
    <!-- http://maven.apache.org/guides/mini/guide-building-for-different environments.html -->
    <id>openshift</id>
    <build>
      <plugins>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>2.4</version>
          <configuration>
            <outputDirectory>target</outputDirectory>
            <warName>ROOT</warName>
          </configuration>
        </plugin>
      </plugins>
    </build>
  </profile>
</profiles>

【讨论】:

  • 感谢 Karl,绝对优雅得多。
【解决方案2】:

我最终使用 maven-antrun-plugin 将 war 复制到 jboss 独立文件夹中。

    <profile>
        <id>openshift</id>
            <properties>
                <axis2.repo.path>/opt/eap/custom_modules</axis2.repo.path>
                <ssl.cacerts.java.path>${java.home}/lib/security/cacerts</ssl.cacerts.java.path>
            </properties>
        <build>
            <resources>
                <resource>
                    <directory>/src/webapp/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>install</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <tasks>
                                    <copy todir="${jboss.deploy.path}">
                                        <fileset dir="${compiled.war.location}"/>
                                    </copy>
                                    <echo>war copied to ${jboss.deploy.path}</echo>

                                </tasks>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

【讨论】:

    猜你喜欢
    • 2012-03-19
    • 2017-02-02
    • 1970-01-01
    • 2021-09-04
    • 2012-03-11
    • 2016-12-30
    • 2011-07-21
    • 1970-01-01
    • 2010-12-15
    相关资源
    最近更新 更多