2

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

  1. 常见的
  2. Webapp 我的项目结构如下:

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

有没有人设法做到这一点?

4

2 回答 2

2

我认为有一个更好的方法,那就是在你的 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>
于 2017-11-04T13:13:09.167 回答
0

我最终使用 maven-antrun-plugin 将战争复制到 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>
于 2017-07-04T15:24:14.300 回答