如何使用 Travis CI 将 Java Web 应用程序部署到 OpenShift WildFly 服务器?

How to deploy a Java web application with Travis CI to an OpenShift WildFly server?

我想使用 Travis CI 将我的 Web 应用程序从 GitHub 部署到我在 OpenShift 上的 WildFly 应用程序服务器。

我遵循了 How to Build and Deploy OpenShift Java Projects using Travis CI 教程,但我的 Java EE 7 网络应用程序中的 index.html 页面没有显示。我得到的是 OpenShift 的默认页面,而不是 index.html 页面,上面写着:"Welcome to your WildFly 8 application on OpenShift".

我必须做什么才能显示我的 webapp?

这是我的 Travis CI 控制台日志的最后几行:

remote: [WARNING] The requested profile "openshift" could not be activated because it does not exist.
remote: Preparing build for deployment
remote: Deployment id is 20db7c5e
remote: Activating deployment
remote: HAProxy already running
remote: HAProxy instance is started
remote: Deploying WildFly
remote: ls: cannot access /var/lib/openshift/54e7963efcf933b7e2000037/app-root/runtime/repo//deployments: No such file or directory
remote: Starting wildfly cart
remote: Found 127.9.239.1:8080 listening port
remote: Found 127.9.239.1:9990 listening port
remote: /var/lib/openshift/54e7963efcf933b7e2000037/wildfly/standalone/deployments /var/lib/openshift/54e7963efcf933b7e2000037/wildfly
remote: /var/lib/openshift/54e7963efcf933b7e2000037/wildfly
remote: CLIENT_MESSAGE: Artifacts deployed: ./ROOT.war
remote: -------------------------
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success

你可以在这里查看我的 webapp 代码:https://github.com/welovecoding/javeasy

可以在以下位置看到部署:http://www.javeasy.com/

我发现了问题。 我没有在 pom.xml 中定义 openshift 配置文件。声明 openshift 配置文件解决了我的问题。

这是我的 pom.xml 作为参考:

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

  <groupId>com.javeasy</groupId>
  <artifactId>javeasy</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>javeasy</name>

  <properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.executable>${env.OPENSHIFT_WILDFLY_DIR}usr/lib/jvm/jdk1.8.0_05/bin/javac</maven.compiler.executable>
    <maven.compiler.fork>true</maven.compiler.fork>
  </properties>

  <dependencies>
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <version>7.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <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>
        <finalName>jbosswildfly</finalName>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
              <failOnMissingWebXml>false</failOnMissingWebXml>
              <outputDirectory>deployments</outputDirectory>
              <warName>ROOT</warName>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

这是我的 .travis.yml:

# http://docs.travis-ci.com/user/workers/container-based-infrastructure/
sudo: false

# http://docs.travis-ci.com/user/languages/java/
language: java
jdk:
  - oraclejdk8

# http://docs.travis-ci.com/user/deployment/openshift/
deploy:
  provider: openshift
  user: me@mail.com
  password:
    secure: ...=
  app: jbosswildfly
  domain: welovecoding
  on:
    repo: welovecoding/javeasy

应用程序 URL 是:jbosswildfly-welovecoding.rhcloud.com

而 GitHub 回购是:https://github.com/welovecoding/javeasy

.travis.yml 已通过 Travis command line client 使用以下命令创建:

travis login
travis setup openshift -r welovecoding/javeasy

参数 -r 定义 GitHub 存储库。