多模块 Maven 项目未部署在 OpenShift (S2I) 上

Multi module maven project not being deployed on OpenShift (S2I)

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

  1. 普通
  2. 网络应用 我的项目结构如下:

    -(root)pom
        -Common  
        -Webapp
    

我们使用带有 S2I(源到图像)部署的 openshift web 控制台。我们选择的图像是Jboss Eap。提供 git 存储库后,Openshift 开始创建所需的资源。它使用 maven 成功编译和安装了我们的模块,但是它没有将它部署到 Jboss 的独立文件夹中。查看构建日志,我们可以检查正在检索的所有依赖项,并在日志末尾检查 BUILD SUCCESS。但是图像 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-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>

我认为有一个更好的方法,就是在你的 web pom 中使用 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>