Thorntail offers an paradigm to packaging and running Enterprise and MicroProfile applications by packaging them with just enough of the server runtime to “java –
First make sure that Openshift / Minishift environment is started. Then, create a new project for your application:
oc new-project thorntail
Now let’s see how to deploy a Thorntail application in it.
Option #1 : Use Java8 Container Image
The first option consists in using the Java8 Container image as a wrapper to execute the thorntail Uber Jar file. We will need at first to import the image from Red Hat Registry:
oc import-image java:8 --from=registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift --confirm
Next, create a new application pointing to a repository which contains a Thorntail application:
oc new-app --name thorntail-java8 'java:8~https://github.com/fmarchioni/mastertheboss' --context-dir='thorntail/thorntail-rest-basic'
Finish, by exposing the Service to a Route:
oc expose svc/thorntail-java8
Option #2 : Use Fabric8 Maven plugin
The second option can be applied directly from your Thorntail project, by including the Fabric8 Maven plugin in a profile. Here’s the pom.xml of our Thorntail application:
<?xml version="1.0"?> <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> <properties> <version.thorntail>2.5.0.Final</version.thorntail> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <failOnMissingWebXml>false</failOnMissingWebXml> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>io.thorntail</groupId> <artifactId>bom-all</artifactId> <version>${version.thorntail}</version> <scope>import</scope> <type>pom</type> </dependency> </dependencies> </dependencyManagement> <groupId>com.mastertheboss.jaxrs</groupId> <artifactId>thorntail-rest-basic</artifactId> <packaging>war</packaging> <version>1.0.0</version> <name>Demo REST Service</name> <url>http://www.mastertheboss.com</url> <dependencies> <dependency> <groupId>io.thorntail</groupId> <artifactId>jaxrs</artifactId> </dependency> <dependency> <groupId>io.thorntail</groupId> <artifactId>cdi</artifactId> </dependency> </dependencies> <build> <finalName>demo</finalName> <plugins> <plugin> <groupId>io.thorntail</groupId> <artifactId>thorntail-maven-plugin</artifactId> <version>${version.thorntail}</version> <executions> <execution> <goals> <goal>package</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <profiles> <profile> <id>openshift</id> <build> <plugins> <plugin> <groupId>io.fabric8</groupId> <artifactId>fabric8-maven-plugin</artifactId> <version>3.5.40</version> <executions> <execution> <goals> <goal>resource</goal> <goal>build</goal> </goals> </execution> </executions> <configuration> <generator> <includes> <include>thorntail-v2</include> </includes> <excludes> <exclude>webapp</exclude> </excludes> </generator> <enricher> <config> <thorntail-v2-health-check> <path>/</path> </thorntail-v2-health-check> </config> </enricher> <resources> <env> <AB_OFF>true</AB_OFF> <JAVA_OPTIONS>-Djava.net.preferIPv4Stack=true</JAVA_OPTIONS> </env> </resources> </configuration> </plugin> </plugins> </build> </profile> </profiles> </project>
Deploy the application on Openshift as follows:
mvn fabric8:deploy -Popenshift -DskiptTests=true
And here is our application deployed on Openshift using both strategies:
Enjoy Thorntail on Openshift!
Source code for this example: https://github.com/fmarchioni/mastertheboss/tree/master/thorntail/thorntail-rest-basic