3

I'm working on a maven multi module application, which consists of two modules:

  1. Common
  2. Webapp My project structure is as follow:

    -(root)pom
        -Common  
        -Webapp
    

We're using openshift web console with S2I (source to image) deploy. The image that we choose is Jboss Eap. After providing git repository, Openshift starts to create required resources. It successfully compile and install our modules using maven, however it does not deploy it on standalone folder for Jboss. Looking at the build log, we can check all dependencies being retrieve and BUILD SUCCESS at end of log. But no artifact deployed on image jboss folder. We can confirm this either by looking at the log or using console to check pod files.

This project is on bitbucket

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

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

And finally, the web 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>

Does anyone manage to achieve this?

Bruno Moreira
  • 175
  • 3
  • 15
  • I have tried to include maven parameters as show here, but no luck: https://stackoverflow.com/questions/39104003/how-to-deploy-multi-module-maven-spring-boot-application-on-openshift – Bruno Moreira Jun 06 '17 at 13:53
  • I lack any real knowledge of deploying Java, but maybe this will help explain what is required. https://blog.openshift.com/maven-multi-module-projects-and-openshift/ – Graham Dumpleton Jun 07 '17 at 03:14
  • What do you get for ``oc set env bc/yourappname --list``? – Graham Dumpleton Jun 07 '17 at 03:21
  • Thanks guys. The purpose was to deploy as fast as we can, without creating custom script or image. We can S2I from web console, in two minutes. The cons side is that S2I is suitable for CI and CD, as you might need the same artifact deployed on all pods. – Bruno Moreira Nov 06 '17 at 11:33

2 Answers2

2

There is a better way I think, which is to use the openshift profile in your web pom. This goes back to the way it was done in V2. In the openshift profile, which will get invoked during the build, copy the .war file into the deployment directory. The only difference I noticed was the deployments directory was named target instead of webapps, but I didn't do any detailed test since target seems to work. E.g.:

<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>
K.Nicholas
  • 10,956
  • 4
  • 46
  • 66
0

I end up using maven-antrun-plugin to copy war into jboss standalone folder.

    <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>
Bruno Moreira
  • 175
  • 3
  • 15