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

时间:2015-02-20 21:58:50

标签: continuous-integration openshift travis-ci java-ee-7 wildfly-8

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

我按照How to Build and Deploy OpenShift Java Projects using Travis CI教程,但我的Java EE 7网络应用程序中的index.html页面没有显示。而不是index.html页面,我获得了OpenShift的默认页面,并说:"欢迎使用OpenShift上的WildFly 8应用程序"。

我需要做什么才能显示我的网络应用程序?

以下是我的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

您可以在此处查看我的网络应用代码:https://github.com/welovecoding/javeasy

可以在http://www.javeasy.com/

上看到部署

1 个答案:

答案 0 :(得分:3)

我发现了问题。我没有在openshift中定义pom.xml个人资料。声明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

应用程序网址为: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存储库。