refactored hello-java app to use thorntail
This commit is contained in:
parent
de664729bc
commit
be6db34b37
7 changed files with 45 additions and 104 deletions
|
|
@ -13,7 +13,7 @@ RUN yum install -y --disableplugin=subscription-manager java-1.8.0-openjdk-hea
|
||||||
mkdir -p /opt/app-root/bin
|
mkdir -p /opt/app-root/bin
|
||||||
|
|
||||||
# Copy the runnable fat JAR to the container.
|
# Copy the runnable fat JAR to the container.
|
||||||
ADD https://github.com/RedHatTraining/DO288-apps/releases/download/1.0/hello-swarm.jar /opt/app-root/bin/
|
ADD https://github.com/RedHatTraining/DO288-apps/releases/download/OCP-4.1-1/hello-java.jar /opt/app-root/bin/
|
||||||
|
|
||||||
COPY run-app.sh /opt/app-root/bin/
|
COPY run-app.sh /opt/app-root/bin/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.redhat.training.openshift</groupId>
|
<groupId>com.redhat.training.openshift</groupId>
|
||||||
<artifactId>hello-swarm</artifactId>
|
<artifactId>hello-java</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<name>Red Hat Training ToT app</name>
|
<name>Red Hat Training Hello Java app</name>
|
||||||
<description>Hello microservice using WildFly Swarm</description>
|
<description>Hello microservice using Thorntail</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- Explicitly declaring the source encoding eliminates the following
|
<!-- Explicitly declaring the source encoding eliminates the following
|
||||||
|
|
@ -17,9 +17,10 @@
|
||||||
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
|
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
|
||||||
resources, i.e. build is platform dependent! -->
|
resources, i.e. build is platform dependent! -->
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||||
|
|
||||||
<!-- JBoss dependency versions -->
|
<!-- Thorntail dependency versions -->
|
||||||
<version.wildfly.swarm>2017.10.0</version.wildfly.swarm>
|
<version.thorntail>2.4.0.Final</version.thorntail>
|
||||||
|
|
||||||
<!-- other plugin versions -->
|
<!-- other plugin versions -->
|
||||||
<version.compiler.plugin>3.1</version.compiler.plugin>
|
<version.compiler.plugin>3.1</version.compiler.plugin>
|
||||||
|
|
@ -35,33 +36,25 @@
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill
|
|
||||||
of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
|
|
||||||
of artifacts. We use this here so that we always get the correct versions
|
|
||||||
of artifacts. -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wildfly.swarm</groupId>
|
<groupId>io.thorntail</groupId>
|
||||||
<artifactId>bom</artifactId>
|
<artifactId>bom-all</artifactId>
|
||||||
<version>${version.wildfly.swarm}</version>
|
<version>${version.thorntail}</version>
|
||||||
<type>pom</type>
|
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
|
<type>pom</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wildfly.swarm</groupId>
|
<groupId>io.thorntail</groupId>
|
||||||
<artifactId>jaxrs-jsonp</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wildfly.swarm</groupId>
|
|
||||||
<artifactId>jaxrs-cdi</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wildfly.swarm</groupId>
|
|
||||||
<artifactId>cdi</artifactId>
|
<artifactId>cdi</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.thorntail</groupId>
|
||||||
|
<artifactId>jaxrs</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
@ -70,23 +63,12 @@
|
||||||
given to the generated war, and hence the context root) -->
|
given to the generated war, and hence the context root) -->
|
||||||
<finalName>hello</finalName>
|
<finalName>hello</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<!-- The Thorntail Maven plugin creates an uber jar -->
|
||||||
|
<!-- To use, run: mvn thorntail:run -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
<groupId>io.thorntail</groupId>
|
||||||
<version>${version.war.plugin}</version>
|
<artifactId>thorntail-maven-plugin</artifactId>
|
||||||
<configuration>
|
<version>${version.thorntail}</version>
|
||||||
<!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
|
|
||||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<!-- The WildFly Swarm plugin creates an uber jar -->
|
|
||||||
<!-- To use, run: mvn wildfly-swarm:run -->
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.wildfly.swarm</groupId>
|
|
||||||
<artifactId>wildfly-swarm-plugin</artifactId>
|
|
||||||
<version>${version.wildfly.swarm}</version>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>com.redhat.training.openshift.hello.Main</mainClass>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
|
@ -98,5 +80,4 @@
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,12 @@ public class HelloResource {
|
||||||
String hostname = System.getenv().getOrDefault("HOSTNAME", "unknown");
|
String hostname = System.getenv().getOrDefault("HOSTNAME", "unknown");
|
||||||
String message = System.getenv().getOrDefault("APP_MSG", null);
|
String message = System.getenv().getOrDefault("APP_MSG", null);
|
||||||
String response = "";
|
String response = "";
|
||||||
|
|
||||||
if (message == null)
|
if (message == null)
|
||||||
response = "Hello world from host "+hostname+"\n";
|
response = "Hello world from host "+hostname+"\n";
|
||||||
else
|
else
|
||||||
response = "Hello world from host ["+hostname+"]. Message received = "+message+"\n";
|
response = "Hello world from host ["+hostname+"]. Message received = "+message+"\n";
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
package com.redhat.training.openshift.hello;
|
|
||||||
|
|
||||||
import org.jboss.shrinkwrap.api.ShrinkWrap;
|
|
||||||
import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset;
|
|
||||||
import org.wildfly.swarm.Swarm;
|
|
||||||
import org.wildfly.swarm.undertow.WARArchive;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
// Instantiate the container
|
|
||||||
Swarm swarm = new Swarm(args);
|
|
||||||
|
|
||||||
// Create one or more deployments
|
|
||||||
WARArchive deployment = ShrinkWrap.create(WARArchive.class);
|
|
||||||
|
|
||||||
// Add resource to deployment
|
|
||||||
deployment.addPackage(Main.class.getPackage());
|
|
||||||
deployment.addAllDependencies();
|
|
||||||
|
|
||||||
// Add Web resources
|
|
||||||
deployment.addAsWebInfResource(
|
|
||||||
new ClassLoaderAsset("WEB-INF/web.xml", Main.class.getClassLoader()), "web.xml");
|
|
||||||
deployment.addAsWebInfResource(
|
|
||||||
new ClassLoaderAsset("WEB-INF/beans.xml", Main.class.getClassLoader()), "beans.xml");
|
|
||||||
|
|
||||||
swarm.start().deploy(deployment);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
|
||||||
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="all">
|
|
||||||
</beans>
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
|
|
||||||
|
|
||||||
</web-app>
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
echo "Starting wildfly swarm app..."
|
echo "Starting hello-java app..."
|
||||||
echo "JVM options => $JAVA_OPTIONS"
|
echo "JVM options => $JAVA_OPTIONS"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
java $JAVA_OPTIONS -jar /opt/app-root/bin/hello-swarm.jar
|
java $JAVA_OPTIONS -jar /opt/app-root/bin/hello-java.jar
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue